#include"stdio.h"> #include"conio.h" void main() { float avg,sum=0,count=0; int i,n,a; printf("Enter n no. values: "); printf("\nEnter values:"); for(i=1;i<=i;i++) { scanf("%d",&a); sum=sum+a; if(a==0) { avg=sum/(i-1); printf("\nAverage of %d No's. before 0: =%.1f",i-1,avg); } } getch(); }
Tuesday, September 7, 2010
Avg. Of N No’s. Untill 0.
Find out sum of N Numbers
#include"stdio.h" #include"conio.h" void main() { int i,n,a,sum=0; printf("Enter n no. values: "); scanf("%d",&n); printf("\nEnter values: "); for(i=1;i<=n;i++) { scanf("%d",&a); sum=sum+a; } printf("\n Sum of %d is= %d",n,sum); getch(); }
Find out sum of 10 numbers
#include"stdio.h" #include"conio.h" void main() { int i,n=10,a,sum=0; printf("Enter 10 Number Values:\n"); for(i=1;i<=n;i++) { scanf("%d",&a); sum=sum+a; } printf("\nSum of 10 Number is= %d",sum); getch(); }
Reverse of n Digit number
#include"stdio.h" #include"conio.h" void main() { int i,n,a,sum=0,x; printf("Enter n Digit Number: "); scanf("%d",&n); x=n; printf("\nReverse of %d number is: ",x); for(i=1;i<=n;i++) { a=n%10; n=n/10; printf("%d",a); } printf("%d",n); getch(); }
Odd Till 3 to 30
#include"stdio.h" #include<conio.h> void main() { int a,i,n=30; printf("Odd value till 30 are: \n\n"); a=30/2; for(i=0;i<=n;i++) { if(i%2==1) { if(i==1) printf(" "); else printf("%d ",i); } } getch(); }
Sum of n Digit numbers
#include"stdio.h" #include"conio.h" void main() { int i,n,a,sum=0,x; printf("Enter n Digit Number: "); scanf("%d",&n); x=n; for(i=1;i<=n;i++) { a=n%10; n=n/10; sum=sum+a; } sum=sum+n; printf("\nSum of %d numbers=%d",x,sum); getch(); }
Average of n numbers
#include#include void main( { float avg,sum=0; int i,n,a; printf("Enter n no. values: "); scanf("%d",&n); printf("\nEnter marks"); for(i=1;i<=n;i++) { scanf("%d",&a); sum=sum+a; } avg=sum/n; printf("\naverage marks=%.1f",avg); getch(); }
Subscribe to:
Posts (Atom)