Posts

Showing posts from August, 2019

22. Write a program to calculate average and total of 5 students for 3 subjects (use nested for loops)

Image
#include<stdio.h> #include<conio.h> void main() { int i,j,std[5][3]; float sum[5],avg[5]; printf("Enter the marks of students:\n"); for(i=0;i<5;i++) { for(j=0;j<3;j++) { scanf("%d",&std[i][j]); } } for(i=0;i<5;i++) { for(j=0;j<3;j++) { printf("%d  ",std[i][j]); } printf("\n"); } for(i=0;i<5;i++) { for(j=0;j<3;j++) { sum[i]=sum[i]+std[i][j]; } } for(i=0;i<5;i++) { for(j=0;j<3;j++) { avg[i]=sum[i]/3; } } for(i=0;i<5;i++) { printf("sum[%d]=%f   ",i,sum[i]); printf("avg[%d]=%f\n",i,avg[i]); } getch(); } #OUTPUTS:

21. Write a C program to find the sum and average of different numbers which are accepted by user as many as user wants

Image
#include<stdio.h> #include<conio.h> void main() { int a,c[100],i; float avg,sum=0; printf("How many numbers do you want to enter: "); scanf("%d",&a); printf("Enter the Numbers:\n"); for(i=0;i<a;i++) { scanf("%d",&c[i]); } for(i=0;i<a;i++) { sum=sum+c[i]; } avg=sum/a; printf("Sum is %f\n Avg is %f",sum,avg); } #OUTPUT:

20. Write a program to find out sum of first and last digit of a given number.

Image
#include<stdio.h> #include<conio.h> void main() { int fd,ld,sum,num; printf("Enter your number:"); scanf("%d",&num); if(num>9) { ld=num%10; while(num>9) { num=num/10; } fd=num; sum=fd+ld; printf("Sum of first digit and last digit is %d",sum); } else { printf("You entered one digit no %d",num); } getch(); } #OUTPUT:

19. Write a program to generate first n number of Fibonacci series

Image
#include<stdio.h> #include<conio.h> void main() { int n,a=0,b=1,c,i; printf("Enter the number:"); scanf("%d",&n); printf("0"); for(i=1;i<=n;i++) { c=a+b; a=b; b=c; printf("%d",a,b); } getch(); } #OUTPUT:

18. Write a program to reverse a number.

Image
#include<stdio.h> #include<conio.h> void main() { int r,num,sum=0,i; printf("Enter any number you want to reverse: "); scanf("%d",&num); for(i=num;i>0;num++) { r=i%10; sum=sum*10+r; i=i/10; } printf("Reverse is %d",sum); getch(); } #OUTPUT:                     

17. Write a C program to find factorial of a given number

Image
#include<stdio.h> #include<conio.h> void main() { int num,i,fact=1; printf("Enter any number:"); scanf("%d",&num); for(i=num;i>0;i--) { fact=fact*i; } printf("factorial is %d",fact); getch(); } #OUTPUT:

16. Write a C program to input an integer number and check the last digit of number is even or odd.

Image
#include<stdio.h> #include<conio.h> void main() { int last,num; printf("Enter the number: "); scanf("%d",&num); last=num%10; if(last%2 ==0) printf("%d digit is Even",last); else printf("%d digit is odd",last); getch(); } #OUTPUT:

15. Write a C program to find out the Maximum and Minimum number from given 10 numbers

Image
#include<stdio.h> #include<conio.h> void main() { int a[10],i,max=0,min=a[0]; printf("Enter 10 numbers:\n"); for(i=0;i<10;i++) { scanf("%d",&a[i]); } for(i=0;i<10;i++) { if(max<a[i]) { max=a[i];         } } printf("Max number is: %d\n",max); for(i=0;i<10;i++) { if(min>>a[i]) { min=a[i]; } } printf("Min number is: %d",min); getch(); } #OUTPUT:

14. Write a C program to read no 1 to 7 and print relatively day Sunday to Saturday.

Image
#include<stdio.h> #include<conio.h> void main() { int day; printf("Enter the no from 1 to 7 to find corresponding : "); scanf("%d",&day); switch (day) { case 1: printf("Sunday"); break; case 2: printf("Monday"); break; case 3: printf("Tuesday"); break; case 4: printf("Wednesday"); break; case 5: printf("Thursday"); break; case 6: printf("Friday"); break; case 7: printf("Saturday"); break; default: printf("Enter the proper input\n"); break; } getch(); } #OUTPUT:

13. Write a c program to prepare pay slip using following data. Da = 10% of basic, Hra = 7.50% of basic, Ma = 300, Pf = 12.50% of basic, Gross = basic + Da + Hra + Ma, Nt = Gross – Pf.

Image
#include<stdio.h> #include<conio.h> void main() { float da,ma,hra,pf,gross,nt,basic; printf("               Payslip                  \n"); printf("----------------------------------------\n"); printf("Enter the Basic salary: "); scanf("%f",&basic); da=(10*basic)/100; ma=300; pf=((12.5)*basic)/100; hra=((7.5)*basic)/100; gross=basic+da+hra+ma; nt=gross-pf; printf("da=%f                         ma=%f\n",da,ma); printf("hra=%f                        pf=%f\n",hra,pf); printf("----------------------------------------\n"); printf("               gross=%f                 \n",gross); printf("               nt=%f...

12. Write a program to read marks from keyboard and your program should display equivalent grade according to following table(if else ladder) Marks Grade 100 - 80 Distinction 79 - 60 First Class 59 - 40 Second Class < 40 Fail

Image
#include<stdio.h> #include<conio.h> void main() { int a; printf("Enter the marks= "); scanf("%d",&a); if(a<=100 && a>=80) printf("Pass with Distinction",a); else if(a<=79 && a>=60) printf("Pass with First class",a); else if(a<=59 && a>=40) printf("Pass with Second class",a); else printf("Student is fail",a); getch(); } #OUTPUT:

11. Write a C program to check whether the entered character is capital, small letter, digit or any special character.

Image
#include<stdio.h> #include<conio.h> void main() { char ch; printf("Enter any character="); scanf("%c",&ch); if(ch>='a' && ch<='z') printf("%c is a small letter",ch); else if(ch>='A' && ch<='Z') printf("%c is Capital letter",ch); else if(ch>='0' && ch<='9') printf("%c is a Numeric",ch); else printf("%c is a Special Character",ch); getch(); } #OUTPUT:

10. Write a program to read three numbers from keyboard and find out maximum out of these three. (nested if else)

Image
#include<stdio.h> #include<conio.h> void main() { int a,b,c; printf("Enter three numbers:\n"); scanf("%d %d %d",&a,&b,&c); if(a>b) { if(a>c) printf("%d is max",a); else printf("%d is max",c); } else { if(b>c) printf("%d is max",b); else printf("%d is max",c); } getch(); } #OUTPUT:

9. Write a program to read marks of a student from keyboard whether the student is pass or fail( using if else)

Image
#include<stdio.h> #include<conio.h> void main() { int a; printf("Enter the marks="); scanf("%d",&a); if(a>=33) printf("Student is Pass"); else printf("Student is Fail"); getch(); } #OUTPUT:

8. Write a C program to find that the accepted number is Negative, or Positive or Zero.

Image
#include<stdio.h> #include<conio.h> void main() { int a; printf("Enter the number you want to check:"); scanf("%d",&a); if(a>0) printf("%d is positive number",a); else if(a<0) printf("%d is negative number",a); else printf("%d is zero",a); getch(); } #OUTPUT:

7. Write a C program to find out distance travelled by the equation d = ut + at^2

Image
#include<stdio.h> #include<conio.h> #include<math.h>             //Here we are using math.h header file because of the function 'pow' .It                                                     only works under the header file math.h void main() { float d,u,a,t; printf("u="); scanf("%f",&u); printf("a="); scanf("%f",&a); printf("t="); scanf("%f",&t); d=(a*t)+(a*pow(t,2)); printf("distance=%f",d); getch(); } #OUTPUT:

6. Write a program to compute Fahrenheit from centigrade (f=1.8*c +32)

Image
#include<stdio.h> #include<conio.h> void main() { float c,fr; printf("Celsius="); scanf("%f",&c); fr=((1.8)*c+32); printf("Fahrenheit=%f",fr); getch(); } #Output:

5. Write a C program to enter a distance in to kilometre and convert it in to meter, feet, inches and centimetre

Image
#include<stdio.h> #include<conio.h> void main() { int km,m,feet,inch,cm; printf("Enter km="); scanf("%d",&km); m=km*1000; feet=km*30*100000; inch=km*(2.54)*100000; cm=km*100000; printf("m=%d\n feet=%d\n inch=%d\n cm=%d\n",m,feet,inch,cm); getch(); } #Output:

4. Write a C program to interchange two numbers.

Image
#include<stdio.h> #include<conio.h> void main() { int a,b,c; printf("a="); scanf("%d",&a); printf("b="); scanf("%d",&b); printf("Before interchange a=%d b=%d\n",a,b); c=a; a=b; b=c; printf("After interchange a=%d b=%d",a,b); getch(); } #Output:

3. Write a program to calculate simple interest (i = (p*r*n)/100 ) i = Simple interest p = Principal amount r = Rate of interest n = Number of years

Image
#include<stdio.h> #include<conio.h> void main() { float p,r,n,si; pintf("p="); scanf("%f",&p); printf("r="); scanf("%f",&r); printf("n="); scanf("%f",&n); si=(p*r*n)/100; printf("Simple Interest=%f",si); getch(); } #Output:

2. Write a program to find area of triangle(a=h*b*.5) a = area h = height b = base

Image
#include<stdio.h> #include<conio.h> void main() { float height,base,area; printf("Enter height="); scanf("%f",&height); printf("Enter base="); scanf("%f",&base); area=height*base*(0.5); printf("Area=%f",area); getch(); } #Output:

1. Write a program to that performs as calculator ( addition, multiplication, division, subtraction)

Image
#include<stdio.h> #include<conio.h> void main() { float a,b,add,sub,div,multi; a=6; b=5; add=a+b; sub=a-b; div=a/b; multi=a*b; printf(" addition=%f\n subtraction=%f\n division=%f \n multiplication=%f\n",add,sub,div,multi); getch(); } #Output: