SlideShare une entreprise Scribd logo
1  sur  12
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
Program 1: write a program to find simple interest by using formula: SI=(p*r*t)/100?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int p, t;
float si, r;
clrscr();
printf("enter principal amount, rate and timen");
scanf("%d %d %f", &p, &t, &r);
si=(p*r*t)/100;
printf("n simple interest=%f", si);
getch();
}
Output: (For example if principal amount=100000, rate=10 and time=4.)
enter principal amount, rate and time
100000
10
4
simple interest=40000
Program 2: write a program for conversion of C°
temperature to F°
temperature?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
float f, c;
clrscr();
printf("enter temperature in C°
n");
scanf("%f", &c);
f=((9*c)/5)+32;
printf("temperature in F°
=%f", f);
getch();
}
Output: (For example if temperature= 10 C°
.)
enter temperature in C°
10
temperature in F°
=50
Inputpart
Processingpart
outputpart
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
Program 3: write a program to find greater number between two numbers?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
clrscr();
printf("enter two numbersn");
scanf("%d %d", &a, &b);
if(a>b)
{
printf("a=%d is greater than b=%d", a,b);
}
else
{
printf("b=%d is greater than a=%d", b,a);
}
getch();
}
Output: (For example if a=17 and b=12.)
enter two numbers
17
12
a=17 is greater than b=12
Program 4: write a program to find greater number between three numbers?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c;
clrscr();
printf("enter three numbersn");
scanf("%d %d %d", &a, &b, &c);
if((a>b)&&(a>c))
{
printf("a=%d is greater", a);
}
else
{
if(b>c)
{
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
printf("b=%d is greater", b);
}
else
{
printf("c=%d is greater", c);
}
}
getch();
}
Output: (For example if a=17, b=12 and c=89.)
enter three numbers
17
12
89
c=89 is greater
Program 5: write a program to find out the division of the student from marks of five subjects?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c, d, e;
float avg;
clrscr();
printf("enter your marks in mathsn");
scanf("%d",&a);
printf("nenter your marks in sciencen");
scanf("%d",&b);
printf("nenter your marks in hindin");
scanf("%d",&c);
printf("nenter your marks in englishn");
scanf("%d",&d);
printf("nenter your marks in social studiesn");
scanf("%d",&e);
if((a<33)||(b<33)||(c<33)||(d<33)||(e<33))
{
printf("you are fail");
}
else
{
avg=(a+b+c+d+e)/5;
if(avg>=75)
{
printf("nfirst division");
}
else if((avg<75)&&(avg>=55))
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
{
printf("nsecond division");
}
else
{
printf("n third division");
}
}
getch();
}
Output: (for ex: marks In maths=92, science=85, hindi=88, english=82 and social studies=90.)
enter your marks in maths
92
enter your marks in science
85
enter your marks in hindi
88
enter your marks in english
82
enter your marks in social studies
90
first division
Program 6: write a program to calculate area and circumference of a circle as per user need?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int x,r;
float a, c, p=3.14;
clrscr();
printf("choose your option:n press 1 to calculate area of a circle n press 2 to calculate
circumference of a circlen");
scanf("%d", &x);
if(x==1)
{
printf("enter radiusn");
scanf("%d",&r);
a=p*r*r;
printf("n area=%f",a);
}
else
{
printf("enter radiusn");
scanf("%d",&r);
c=2*p*r;
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
printf("n circumference=%f",c);
}
getch();
}
Output: (for ex: user want to calculate area of a circle and radius=7.)
choose your option:
press 1 to calculate area of a circle
press 2 to calculate circumference of a circle
1
enter radius
7
area=153.86
Program 7: write a program to calculate gross salary, if dearness allowance is 40% and house
rent allowance is 20% of the basic salary?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
float da,hra,gs,bs;
clrscr();
printf("enter your basic salary");
scanf("%f",&bs);
da=(bs*40/100);
hra=(bs*20/100);
gs=bs-hra-da;
printf("n your gross salary is=%f", gs);
getch();
}
Or;
#include<stdio.h>
#include<conio.h>
void main()
{
float da,hra,gs;
int bs;
clrscr();
printf("n enter your basic salary");
scanf("%d",&bs);
da=(0.4*bs);
hra=(0.2*bs);
gs=bs-hra-da;
printf("n your gross salary is=%f", gs);
getch();
}
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
Or;
#include<stdio.h>
#include<conio.h>
void main()
{
float da,hra,gs;
int bs;
clrscr();
printf("enter your basic salaryn");
scanf("%d",&bs);
da=(40.0/100)*bs;
hra=(20.0/100)*bs;
gs=bs-hra-da;
printf("n your gross salary is=%f", gs);
getch();
}
As, we have discussed integer float conversion previously:
You know if an integer value is divided by another integer value and in case the answer is float
type then also, only integer part of the answer we will get as result.
That’s why I had showed you three ways of calculating da and hra.
In first way; as bs itself is float type therefore, when it will be multiplied by 40 the result will be
considered as float type so that after division by100, We will get da=0.40000 (same thing apply
for hra.)
In second approach, as bs is integer type that’s why we have directly multiplied it 0.4 and 0.2.
because here, (bs*40/100); will not work. As, 40 (is integer type) and 100(is also integer type),
therefore, integer/ integer= integer. Due to which, 40/100=0 and bs*0=0. (same thing applies
with hra. )
In third approach; as bs in integer type that’s why we have written equations like;
da=(40.0/100)*bs;
hra=(20.0/100)*bs;
as, 40.0 is real type divided by 100(integer type ) and real/integer=real value.
Therefore, it will work perfectly;
40.0/100=0.40000
0.40000*bs= (required float value according to bs value.)
Output: (for ex: basic salary=25000)
enter your basic salary
25000
your gross salary is=10000.00
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
Program 8: write a program to identify vowels and consonants?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
char x;
clrscr();
printf("enter any alphabet in small casen");
scanf("%c", &x);
if(x=='a'||x=='e'|| x=='i'|| x=='o'|| x=='u')
{
printf("you have entered a vowel");
}
else
{
printf("you have entered a consonant");
}
getch();
}
Output: (for ex: user has entered a)
enter any alphabet in small case
a
you have entered a vowel
Program 9: write a program to identify even and odd number?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,m;
clrscr();
printf("enter any integer type valuen");
scanf("%d", &n);
m=n%2;
if(m==0)
{
printf("number is even");
}
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
else
{
printf("number is odd");
}
getch();
}
Or;
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("enter any integer type value");
scanf("%d", &n);
if(n%2)
{
printf("number is odd");
}
else
{
printf("number is even");
}
getch();
}
In second approach we have used concept of 0 implies false and 1 implies true. Therefore;
when n%2=0, it will indicate false and control goes to else statement and in other cases if
statement will be executed.
Output: (for example user has entered 21)
enter any integer type value
21
number is odd
Explaination: (according to second approach)
as 21%2 is equal to 1 (moduls operator gives remainder). Therefore if statement will be
executed.
Program 10: write a program to swap two numbers without using third variable?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
clrscr();
printf("enter two numbers n");
scanf("%d%d",&a, &b);
printf("n before swap a=%d and b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("n after swap a=%d and b=%d",a,b);
getch();
}
Output: (for ex: a=25 and b=16)
enter two numbers
25
16
before swap a=25 and b=16
after swap a=16 and b=25
Program 11: write a program to swap two numbers using bitwise ex-or operator?
Solution:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter two numbers n");
scanf("%d%d",&a, &b);
printf("n before swap a=%d and b=%d",a,b);
a=a^b;
b=a^b;
a=a^b;
printf("n after swap a=%d and b=%d",a,b);
getch();
}
Let us take an example to understand how this concept works:
Lets; a=5 and b=6, therefore;
a=a^b;
a= 0101
b= 0110
a^b=0011
Similarly; at second step:
b=a^b; and after first step a=3 and b=6
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com
a= 0011
b= 0110
a^b=0101
now, a=3 and b=5
similarly, at third step:
a=a^b;
a= 0101
b= 0101
a^b=0110
now, a=6 and b=5. (This is our required answer.)
Output: (as: a=5 and b=6)
enter two numbers
5
6
before swap a=5 and b=6
after swap a=6 and b=5
More than 100 programs of c language are available withcompletetheory.Justloginto
www.eakanchha.com

Contenu connexe

Tendances

Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 

Tendances (20)

Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
C Programming
C ProgrammingC Programming
C Programming
 
C code examples
C code examplesC code examples
C code examples
 
C important questions
C important questionsC important questions
C important questions
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
week-3x
week-3xweek-3x
week-3x
 
Revision1 C programming
Revision1 C programmingRevision1 C programming
Revision1 C programming
 
Let us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionLet us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solution
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
 
Input And Output
 Input And Output Input And Output
Input And Output
 
Revision1schema C programming
Revision1schema C programmingRevision1schema C programming
Revision1schema C programming
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 

Similaire à programs of c www.eakanchha.com

Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
nayakq
 

Similaire à programs of c www.eakanchha.com (20)

Programming egs
Programming egs Programming egs
Programming egs
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Progr3
Progr3Progr3
Progr3
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
 
C file
C fileC file
C file
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
C Programming
C ProgrammingC Programming
C Programming
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
C lab
C labC lab
C lab
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
comp2
comp2comp2
comp2
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
C programs
C programsC programs
C programs
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 

Plus de Akanchha Agrawal

Plus de Akanchha Agrawal (7)

Micro economics questions sets
Micro economics questions setsMicro economics questions sets
Micro economics questions sets
 
Number system with conversions www.eakanchha.com
Number system with conversions www.eakanchha.comNumber system with conversions www.eakanchha.com
Number system with conversions www.eakanchha.com
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.com
 
Lvp law of variable proportions www.eakanchha.com
Lvp law of variable proportions www.eakanchha.comLvp law of variable proportions www.eakanchha.com
Lvp law of variable proportions www.eakanchha.com
 
cost missing value question www.eakanchha.com
 cost missing value question www.eakanchha.com cost missing value question www.eakanchha.com
cost missing value question www.eakanchha.com
 
cost missing value question www.eakanchha.com
 cost missing value question www.eakanchha.com cost missing value question www.eakanchha.com
cost missing value question www.eakanchha.com
 
cost micro economics www.eakanchha.com
cost micro economics www.eakanchha.comcost micro economics www.eakanchha.com
cost micro economics www.eakanchha.com
 

Dernier

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Dernier (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

programs of c www.eakanchha.com

  • 1. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com
  • 2. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com Program 1: write a program to find simple interest by using formula: SI=(p*r*t)/100? Solution: #include<stdio.h> #include<conio.h> void main() { int p, t; float si, r; clrscr(); printf("enter principal amount, rate and timen"); scanf("%d %d %f", &p, &t, &r); si=(p*r*t)/100; printf("n simple interest=%f", si); getch(); } Output: (For example if principal amount=100000, rate=10 and time=4.) enter principal amount, rate and time 100000 10 4 simple interest=40000 Program 2: write a program for conversion of C° temperature to F° temperature? Solution: #include<stdio.h> #include<conio.h> void main() { float f, c; clrscr(); printf("enter temperature in C° n"); scanf("%f", &c); f=((9*c)/5)+32; printf("temperature in F° =%f", f); getch(); } Output: (For example if temperature= 10 C° .) enter temperature in C° 10 temperature in F° =50 Inputpart Processingpart outputpart
  • 3. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com Program 3: write a program to find greater number between two numbers? Solution: #include<stdio.h> #include<conio.h> void main() { int a, b; clrscr(); printf("enter two numbersn"); scanf("%d %d", &a, &b); if(a>b) { printf("a=%d is greater than b=%d", a,b); } else { printf("b=%d is greater than a=%d", b,a); } getch(); } Output: (For example if a=17 and b=12.) enter two numbers 17 12 a=17 is greater than b=12 Program 4: write a program to find greater number between three numbers? Solution: #include<stdio.h> #include<conio.h> void main() { int a, b, c; clrscr(); printf("enter three numbersn"); scanf("%d %d %d", &a, &b, &c); if((a>b)&&(a>c)) { printf("a=%d is greater", a); } else { if(b>c) {
  • 4. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com printf("b=%d is greater", b); } else { printf("c=%d is greater", c); } } getch(); } Output: (For example if a=17, b=12 and c=89.) enter three numbers 17 12 89 c=89 is greater Program 5: write a program to find out the division of the student from marks of five subjects? Solution: #include<stdio.h> #include<conio.h> void main() { int a, b, c, d, e; float avg; clrscr(); printf("enter your marks in mathsn"); scanf("%d",&a); printf("nenter your marks in sciencen"); scanf("%d",&b); printf("nenter your marks in hindin"); scanf("%d",&c); printf("nenter your marks in englishn"); scanf("%d",&d); printf("nenter your marks in social studiesn"); scanf("%d",&e); if((a<33)||(b<33)||(c<33)||(d<33)||(e<33)) { printf("you are fail"); } else { avg=(a+b+c+d+e)/5; if(avg>=75) { printf("nfirst division"); } else if((avg<75)&&(avg>=55))
  • 5. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com { printf("nsecond division"); } else { printf("n third division"); } } getch(); } Output: (for ex: marks In maths=92, science=85, hindi=88, english=82 and social studies=90.) enter your marks in maths 92 enter your marks in science 85 enter your marks in hindi 88 enter your marks in english 82 enter your marks in social studies 90 first division Program 6: write a program to calculate area and circumference of a circle as per user need? Solution: #include<stdio.h> #include<conio.h> void main() { int x,r; float a, c, p=3.14; clrscr(); printf("choose your option:n press 1 to calculate area of a circle n press 2 to calculate circumference of a circlen"); scanf("%d", &x); if(x==1) { printf("enter radiusn"); scanf("%d",&r); a=p*r*r; printf("n area=%f",a); } else { printf("enter radiusn"); scanf("%d",&r); c=2*p*r;
  • 6. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com printf("n circumference=%f",c); } getch(); } Output: (for ex: user want to calculate area of a circle and radius=7.) choose your option: press 1 to calculate area of a circle press 2 to calculate circumference of a circle 1 enter radius 7 area=153.86 Program 7: write a program to calculate gross salary, if dearness allowance is 40% and house rent allowance is 20% of the basic salary? Solution: #include<stdio.h> #include<conio.h> void main() { float da,hra,gs,bs; clrscr(); printf("enter your basic salary"); scanf("%f",&bs); da=(bs*40/100); hra=(bs*20/100); gs=bs-hra-da; printf("n your gross salary is=%f", gs); getch(); } Or; #include<stdio.h> #include<conio.h> void main() { float da,hra,gs; int bs; clrscr(); printf("n enter your basic salary"); scanf("%d",&bs); da=(0.4*bs); hra=(0.2*bs); gs=bs-hra-da; printf("n your gross salary is=%f", gs); getch(); }
  • 7. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com Or; #include<stdio.h> #include<conio.h> void main() { float da,hra,gs; int bs; clrscr(); printf("enter your basic salaryn"); scanf("%d",&bs); da=(40.0/100)*bs; hra=(20.0/100)*bs; gs=bs-hra-da; printf("n your gross salary is=%f", gs); getch(); } As, we have discussed integer float conversion previously: You know if an integer value is divided by another integer value and in case the answer is float type then also, only integer part of the answer we will get as result. That’s why I had showed you three ways of calculating da and hra. In first way; as bs itself is float type therefore, when it will be multiplied by 40 the result will be considered as float type so that after division by100, We will get da=0.40000 (same thing apply for hra.) In second approach, as bs is integer type that’s why we have directly multiplied it 0.4 and 0.2. because here, (bs*40/100); will not work. As, 40 (is integer type) and 100(is also integer type), therefore, integer/ integer= integer. Due to which, 40/100=0 and bs*0=0. (same thing applies with hra. ) In third approach; as bs in integer type that’s why we have written equations like; da=(40.0/100)*bs; hra=(20.0/100)*bs; as, 40.0 is real type divided by 100(integer type ) and real/integer=real value. Therefore, it will work perfectly; 40.0/100=0.40000 0.40000*bs= (required float value according to bs value.) Output: (for ex: basic salary=25000) enter your basic salary 25000 your gross salary is=10000.00
  • 8. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com Program 8: write a program to identify vowels and consonants? Solution: #include<stdio.h> #include<conio.h> void main() { char x; clrscr(); printf("enter any alphabet in small casen"); scanf("%c", &x); if(x=='a'||x=='e'|| x=='i'|| x=='o'|| x=='u') { printf("you have entered a vowel"); } else { printf("you have entered a consonant"); } getch(); } Output: (for ex: user has entered a) enter any alphabet in small case a you have entered a vowel Program 9: write a program to identify even and odd number? Solution: #include<stdio.h> #include<conio.h> void main() { int n,m; clrscr(); printf("enter any integer type valuen"); scanf("%d", &n); m=n%2; if(m==0) { printf("number is even"); }
  • 9. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com else { printf("number is odd"); } getch(); } Or; #include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("enter any integer type value"); scanf("%d", &n); if(n%2) { printf("number is odd"); } else { printf("number is even"); } getch(); } In second approach we have used concept of 0 implies false and 1 implies true. Therefore; when n%2=0, it will indicate false and control goes to else statement and in other cases if statement will be executed. Output: (for example user has entered 21) enter any integer type value 21 number is odd Explaination: (according to second approach) as 21%2 is equal to 1 (moduls operator gives remainder). Therefore if statement will be executed. Program 10: write a program to swap two numbers without using third variable? Solution: #include<stdio.h> #include<conio.h> void main() { int a,b;
  • 10. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com clrscr(); printf("enter two numbers n"); scanf("%d%d",&a, &b); printf("n before swap a=%d and b=%d",a,b); a=a+b; b=a-b; a=a-b; printf("n after swap a=%d and b=%d",a,b); getch(); } Output: (for ex: a=25 and b=16) enter two numbers 25 16 before swap a=25 and b=16 after swap a=16 and b=25 Program 11: write a program to swap two numbers using bitwise ex-or operator? Solution: #include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("enter two numbers n"); scanf("%d%d",&a, &b); printf("n before swap a=%d and b=%d",a,b); a=a^b; b=a^b; a=a^b; printf("n after swap a=%d and b=%d",a,b); getch(); } Let us take an example to understand how this concept works: Lets; a=5 and b=6, therefore; a=a^b; a= 0101 b= 0110 a^b=0011 Similarly; at second step: b=a^b; and after first step a=3 and b=6
  • 11. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com a= 0011 b= 0110 a^b=0101 now, a=3 and b=5 similarly, at third step: a=a^b; a= 0101 b= 0101 a^b=0110 now, a=6 and b=5. (This is our required answer.) Output: (as: a=5 and b=6) enter two numbers 5 6 before swap a=5 and b=6 after swap a=6 and b=5
  • 12. More than 100 programs of c language are available withcompletetheory.Justloginto www.eakanchha.com