Program 1: write a program to find simple interest by using formula: SI=(p*r*t)/100?
Program 2: write a program for conversion of C° temperature to F° temperature?
Program 3: write a program to find greater number between two numbers?
Program 4: write a program to find greater number between three numbers?
Program 5: write a program to find out the division of the student from marks of five subjects?
Program 6: write a program to calculate area and circumference of a circle as per user need?
Program 7: write a program to calculate gross salary, if dearness allowance is 40% and house rent allowance is 20% of the basic salary?
Program 8: write a program to identify vowels and consonants?
Program 9: write a program to identify even and odd number?
Program 10: write a program to swap two numbers without using third variable?
Program 11: write a program to swap two numbers using bitwise ex-or operator?
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