C programming
1. /*To find sum,difference,product,quotient*/
main()
{
float a,b,sum,difference,product,quotient;
printf("<Enter the value 1:");
scanf("%f",&a);
printf("<Enter the value 2:");
scanf("%f",&b);
sum=a+b;
printf("Sum=%f",sum);
difference=a-b;
printf("\nDifference=%f",difference);
product=a*b;
printf("\nProduct=%f",product);
quotient=a/b;
printf("\nQuotient=%f",quotient);
return 0;
}
2. /*To ask 5 numbers & finding their sum & average*/
main()
{
int a,i,sum;
float average;
sum=0,i=1;
while (i<=5)
{
printf("Enter value number %d:",i);
scanf("%d",&a);
sum=sum+a;
average=sum/5;
i++;
}
printf("The sum of the five numbers =%d",sum);
printf("\nThe average of the five numbers is =%f",average);
return 0;
}
3. /*To find simple interest*/
main()
{
int p,n;
float r,interest;
printf("<enterp>");
scanf("%d",&p);
printf("<entern>");
scanf("%d",&n);
printf("<enterr>");
scanf("%f",&r);
interest=0;
interest=p*n*r/100;
printf("The simple interest=%f",interest);
return 0;
}
4. /*To find area & circumference of circle*/
main()
{
float r,pie,area,circumference;
printf("Enter radius:");
scanf("%f",&r);
pie=3.14;
area=pie*r*r;
printf("\nThe area of circle=%f",area);
circumference=2*pie*r;
printf("\nThe circumference of the circle=%f",circumference);
return 0;
}
5. /*To get the answer in Centigrade*/
main()
{
float F,c;
printf("<enterF>");
scanf("%f",&F);
c=(F-32)*5/9;
printf("The centigrade value =%f",c);
return 0;
}
6. /*To find the difference between post operator & pre operator*/
main()
{
float a,b;
printf("Enter the value a:");
scanf("%f",&a);
printf("<nter the value b:");
scanf("%f",&b);
b=a++;
printf("a=%f",a);
printf("\nb=%f",b);
printf("\nTHIS IS THE EXAMPLE OF POST-OPERATOR");
b=++a;
printf("\na=%f",a);
printf("\nb=%f",b);
printf("\nTHIS IS THE EXAMPLE OF PRE OPEERATOR");
return 0;
}
7. /*To find whether the number entered is even or odd*/
main()
{
int a;
printf("Enter the value a:");
scanf("%d",&a);
if (a%2==0)
{
printf("The number is even");
}
printf("The number is odd");
return 0;
}
8./*To find whether the numbers entered by user are divisible by another*/
main()
{
int a,b;
printf("Enter the value a:");
scanf("%d",&a);
printf("Enter the value b:");
scanf("%d",&b);
if (a%b==0)
printf("The number is divisible");
else
printf("The number is not divisible");
return 0;
}
9. /*To find larger out of the 2 numbers entered*/
main()
{
int a,b,big;
printf("Enter the value a:");
scanf("%d",&a);
printf("Enter the value b:");
scanf("%d",&b);
big=a;
if (a<b)
big=b;
printf("The larger number is %d",big);
return 0;
}
10. /*To find the largest among the three numbers entered*/
main()
{
int a,b,c,big;
printf("Enter the value a:");
scanf("%d",&a);
printf("Enter the value b:");
scanf("%d",&b);
printf("Enter the value c:");
scanf("%d",&c);
big=a;
(b>a)&&(b>c);
big=b;
(c>a)&&(c>b);
big=c;
printf("big=%d",big);
return 0;
}
11. /*To find largest among n numbers entered*/
main()
{
int a,s,n,i;
printf("Enter the size s:");
scanf("%d",&s);
a=0,i=0;
for(i=1;i<=s;i++)
{
printf("Enter the value %d",i;
scanf("%d",&n);
if(n>a)
a=n;
}
printf("Largest value=%d",a);
return 0;
}
12. /*To display first n natural numbers*/
main()
{
int s,i;
printf("Enter the size s:");
scanf("%d",&s);
i=1;
do
{
printf("%d\n",i);
i++;
}
while (i<=s);
return 0;
}
OR
for(i=1;i<=s;i++)
{
printf("%d\n",i);
}
13. /*To find sum & average of n numbers*/
main()
{
int i,s;
float n,sum,average;
sum=0,average=0;
printf("Enter the size:");
scanf("%d",&s);
for(i=1;i<=s;i++)
{
printf("Enter the number:");
scanf("%f",&n);
sum=sum+n;
average=sum/s;
}
printf("The sum is %f",sum);
printf("\nThe average is %f",average);
return 0;
}
14. /*To find the area of n circles*/
main()
{
int s,i=1;
float r,pie,area;
pie=3.14;
printf("Enter the size s:");
scanf("%d",&s);
do
{
printf("\nEnter the radius:");
scanf("%f",&r);
area=pie*r*r;
printf("\nThe area of the circle is =%f",area);
i++;
}
while(i<=s);
return 0;
}
15. /*To find the area & perimeter of n triangles*/
main()
{
int i,l;
float a,b,c,s,area,perimeter;
printf("Enter the size:");
scanf("%d",&l);
area=0,perimeter=0;
for(i=1;i<=l;i++)
{
printf("\nEnter Side a:");
scanf("%f",&a);
printf("Enter Side b:");
scanf("%f",&b);
printf("Enter Side c:");
scanf("%f",&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
perimeter=a+b+c;
printf("THE AREA IS %f" ,area);
printf("\nTHE PERIMETER IS %f",perimeter);
16. /*To display day of the week according to the number entered*/
main()
{
int n;
printf("Enter the number:");
scanf("%d",&n);
switch
{
case 1:
printf("MONDAY");
break;
case 2:
printf("TUESDAY");
break;
case 3:
printf("WEDNESDAY");
break;
case 4:
printf("THURSDAY");
break;
case 5:
printf("FRIDAY");
break;
case 6:
printf("SATURDAY");
break;
case 7:
printf("SUNDAY");
break;
default:
printf("The number is invalid");
}
return 0;
}
17. /*To find the squares of first n natural numbers*/
#include<stdio.h>
main()
{
int s,i,a;
a=0;
printf("Enter the size:");
scanf("%d",&s);
for(i=1;i<=s;i++)
{
a=i*i;
printf("\n%d",a);
}
return 0;
}
18. /*To find the squares of first n even or odd numbers*/
main()
{
int n,i,a;a=1;
printf("Enter the size:");
scanf("%d",&n);
n=n*2;
printf("\n\nThe squares of first n even numbers are as follows:");
for(i=2;i<=n;i++)
{
a=i*i;
i++;
printf("\n%d",a);
}
printf("\n\nThe squares of first n odd numbers are as follows:");
for(i=1;i<=n;i++)
{
a=i*i;
i++;
printf("\n%d",a);
}
return 0;
}
19. /*To find the factorial of the given number*/
main()
{
int i,n;
float fact;
fact=1;
printf("Enter the number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("\nThe factorial of ths given number is %f",fact);
return 0;
}
21. /*Finonacci series*/
main()
{
int a,b,c,n,i;
a=0,b=1,c=0;
printf("Enter size:");
scanf("%d",&n);
printf("\n%d",a);
printf("%d",b);
for(i=3;i<=n;i++)
{
c=a+b;
a=b;
b=c;
printf("%d",c);
}
return 0;
}
22. /*To display a particular pattern*/
main()
{
int i,n,j;
printf("Please insert the size:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("*");
printf("\n");
}
return 0;
}
23. /*To find the result of sum of squares of first n natural numbers*/
main()
{
int n,i,sum,a;
sum=0,a=0;
printf("Enter the size:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
a=i*i;
sum=sum+a;
}
printf("Sum is %d",sum);
return 0;
}
24. /*To display a particular pattern*/
main()
{
int i,n,j;
printf("Please insert the size:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
return 0;
}
25. /*To find the division obtained by a student*/
main()
{
float a,b,c,d,e,p;
printf("Enter the marks of 1st subject:");
scanf("%f",&a);
printf("\nEnter the marks of 2nd subject:");
scanf("%f",&b);
printf("\nEnter the marks of 3rd subject:");
scanf("%f",&c);
printf("\nEnter the marks of 4th subject:");
scanf("%f",&d);
printf("\nEnter the marks of 5th subject:");
scanf("%f",&e);
p=((a+b+c+d+e)*100)/500;
printf("\nYour score is %f%",p);
if (p>=80)
printf("\nCongratulation,you have obtained distinction");
else if(p>=60)
printf("\nWell Done,You have obtained 1st class");
else if(p>=40)
printf("\nNeed more practice,You have obtained 2nd class");
else if(p<40)
printf("\nYou have failed");
return 0;
}
1. /*To find sum,difference,product,quotient*/
main()
{
float a,b,sum,difference,product,quotient;
printf("<Enter the value 1:");
scanf("%f",&a);
printf("<Enter the value 2:");
scanf("%f",&b);
sum=a+b;
printf("Sum=%f",sum);
difference=a-b;
printf("\nDifference=%f",difference);
product=a*b;
printf("\nProduct=%f",product);
quotient=a/b;
printf("\nQuotient=%f",quotient);
return 0;
}
2. /*To ask 5 numbers & finding their sum & average*/
main()
{
int a,i,sum;
float average;
sum=0,i=1;
while (i<=5)
{
printf("Enter value number %d:",i);
scanf("%d",&a);
sum=sum+a;
average=sum/5;
i++;
}
printf("The sum of the five numbers =%d",sum);
printf("\nThe average of the five numbers is =%f",average);
return 0;
}
3. /*To find simple interest*/
main()
{
int p,n;
float r,interest;
printf("<enterp>");
scanf("%d",&p);
printf("<entern>");
scanf("%d",&n);
printf("<enterr>");
scanf("%f",&r);
interest=0;
interest=p*n*r/100;
printf("The simple interest=%f",interest);
return 0;
}
4. /*To find area & circumference of circle*/
main()
{
float r,pie,area,circumference;
printf("Enter radius:");
scanf("%f",&r);
pie=3.14;
area=pie*r*r;
printf("\nThe area of circle=%f",area);
circumference=2*pie*r;
printf("\nThe circumference of the circle=%f",circumference);
return 0;
}
5. /*To get the answer in Centigrade*/
main()
{
float F,c;
printf("<enterF>");
scanf("%f",&F);
c=(F-32)*5/9;
printf("The centigrade value =%f",c);
return 0;
}
6. /*To find the difference between post operator & pre operator*/
main()
{
float a,b;
printf("Enter the value a:");
scanf("%f",&a);
printf("<nter the value b:");
scanf("%f",&b);
b=a++;
printf("a=%f",a);
printf("\nb=%f",b);
printf("\nTHIS IS THE EXAMPLE OF POST-OPERATOR");
b=++a;
printf("\na=%f",a);
printf("\nb=%f",b);
printf("\nTHIS IS THE EXAMPLE OF PRE OPEERATOR");
return 0;
}
7. /*To find whether the number entered is even or odd*/
main()
{
int a;
printf("Enter the value a:");
scanf("%d",&a);
if (a%2==0)
{
printf("The number is even");
}
printf("The number is odd");
return 0;
}
8./*To find whether the numbers entered by user are divisible by another*/
main()
{
int a,b;
printf("Enter the value a:");
scanf("%d",&a);
printf("Enter the value b:");
scanf("%d",&b);
if (a%b==0)
printf("The number is divisible");
else
printf("The number is not divisible");
return 0;
}
9. /*To find larger out of the 2 numbers entered*/
main()
{
int a,b,big;
printf("Enter the value a:");
scanf("%d",&a);
printf("Enter the value b:");
scanf("%d",&b);
big=a;
if (a<b)
big=b;
printf("The larger number is %d",big);
return 0;
}
10. /*To find the largest among the three numbers entered*/
main()
{
int a,b,c,big;
printf("Enter the value a:");
scanf("%d",&a);
printf("Enter the value b:");
scanf("%d",&b);
printf("Enter the value c:");
scanf("%d",&c);
big=a;
(b>a)&&(b>c);
big=b;
(c>a)&&(c>b);
big=c;
printf("big=%d",big);
return 0;
}
11. /*To find largest among n numbers entered*/
main()
{
int a,s,n,i;
printf("Enter the size s:");
scanf("%d",&s);
a=0,i=0;
for(i=1;i<=s;i++)
{
printf("Enter the value %d",i;
scanf("%d",&n);
if(n>a)
a=n;
}
printf("Largest value=%d",a);
return 0;
}
12. /*To display first n natural numbers*/
main()
{
int s,i;
printf("Enter the size s:");
scanf("%d",&s);
i=1;
do
{
printf("%d\n",i);
i++;
}
while (i<=s);
return 0;
}
OR
for(i=1;i<=s;i++)
{
printf("%d\n",i);
}
13. /*To find sum & average of n numbers*/
main()
{
int i,s;
float n,sum,average;
sum=0,average=0;
printf("Enter the size:");
scanf("%d",&s);
for(i=1;i<=s;i++)
{
printf("Enter the number:");
scanf("%f",&n);
sum=sum+n;
average=sum/s;
}
printf("The sum is %f",sum);
printf("\nThe average is %f",average);
return 0;
}
14. /*To find the area of n circles*/
main()
{
int s,i=1;
float r,pie,area;
pie=3.14;
printf("Enter the size s:");
scanf("%d",&s);
do
{
printf("\nEnter the radius:");
scanf("%f",&r);
area=pie*r*r;
printf("\nThe area of the circle is =%f",area);
i++;
}
while(i<=s);
return 0;
}
15. /*To find the area & perimeter of n triangles*/
main()
{
int i,l;
float a,b,c,s,area,perimeter;
printf("Enter the size:");
scanf("%d",&l);
area=0,perimeter=0;
for(i=1;i<=l;i++)
{
printf("\nEnter Side a:");
scanf("%f",&a);
printf("Enter Side b:");
scanf("%f",&b);
printf("Enter Side c:");
scanf("%f",&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
perimeter=a+b+c;
printf("THE AREA IS %f" ,area);
printf("\nTHE PERIMETER IS %f",perimeter);
16. /*To display day of the week according to the number entered*/
main()
{
int n;
printf("Enter the number:");
scanf("%d",&n);
switch
{
case 1:
printf("MONDAY");
break;
case 2:
printf("TUESDAY");
break;
case 3:
printf("WEDNESDAY");
break;
case 4:
printf("THURSDAY");
break;
case 5:
printf("FRIDAY");
break;
case 6:
printf("SATURDAY");
break;
case 7:
printf("SUNDAY");
break;
default:
printf("The number is invalid");
}
return 0;
}
17. /*To find the squares of first n natural numbers*/
#include<stdio.h>
main()
{
int s,i,a;
a=0;
printf("Enter the size:");
scanf("%d",&s);
for(i=1;i<=s;i++)
{
a=i*i;
printf("\n%d",a);
}
return 0;
}
18. /*To find the squares of first n even or odd numbers*/
main()
{
int n,i,a;a=1;
printf("Enter the size:");
scanf("%d",&n);
n=n*2;
printf("\n\nThe squares of first n even numbers are as follows:");
for(i=2;i<=n;i++)
{
a=i*i;
i++;
printf("\n%d",a);
}
printf("\n\nThe squares of first n odd numbers are as follows:");
for(i=1;i<=n;i++)
{
a=i*i;
i++;
printf("\n%d",a);
}
return 0;
}
19. /*To find the factorial of the given number*/
main()
{
int i,n;
float fact;
fact=1;
printf("Enter the number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("\nThe factorial of ths given number is %f",fact);
return 0;
}
21. /*Finonacci series*/
main()
{
int a,b,c,n,i;
a=0,b=1,c=0;
printf("Enter size:");
scanf("%d",&n);
printf("\n%d",a);
printf("%d",b);
for(i=3;i<=n;i++)
{
c=a+b;
a=b;
b=c;
printf("%d",c);
}
return 0;
}
22. /*To display a particular pattern*/
main()
{
int i,n,j;
printf("Please insert the size:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("*");
printf("\n");
}
return 0;
}
23. /*To find the result of sum of squares of first n natural numbers*/
main()
{
int n,i,sum,a;
sum=0,a=0;
printf("Enter the size:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
a=i*i;
sum=sum+a;
}
printf("Sum is %d",sum);
return 0;
}
24. /*To display a particular pattern*/
main()
{
int i,n,j;
printf("Please insert the size:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
return 0;
}
25. /*To find the division obtained by a student*/
main()
{
float a,b,c,d,e,p;
printf("Enter the marks of 1st subject:");
scanf("%f",&a);
printf("\nEnter the marks of 2nd subject:");
scanf("%f",&b);
printf("\nEnter the marks of 3rd subject:");
scanf("%f",&c);
printf("\nEnter the marks of 4th subject:");
scanf("%f",&d);
printf("\nEnter the marks of 5th subject:");
scanf("%f",&e);
p=((a+b+c+d+e)*100)/500;
printf("\nYour score is %f%",p);
if (p>=80)
printf("\nCongratulation,you have obtained distinction");
else if(p>=60)
printf("\nWell Done,You have obtained 1st class");
else if(p>=40)
printf("\nNeed more practice,You have obtained 2nd class");
else if(p<40)
printf("\nYou have failed");
return 0;
}