void main () { int no1, sum, n; clrscr() sum = 0; n = 1; printf("\n enter the number to which sum is to be generated"); scanf("%d",&no1); while(n<=no1) { sum=sum+n; n=n+1 } printf("\n the sum of %d = %d, no1, sum"); getch (); }
/*mycfiles.wordpress.com To Calculate Sum & Average of 4 no.*/ #include<stdio.h> #include<conio.h> void main() { float a,b,c,d,sum,avg; clrscr(); printf("Enter the 4 nos.\n\n"); scanf("%f%f%f%f",&a,&b,&c,&d); sum=a+b+c+d; avg=(a+b+c+d)/4; printf("\nSum is= %f\nAverage is= %f",sum,avg); getch(); }
The sum of n and 5 is n+ 5
Find the Sum to n terms of the series 5 5+55+555+ +n Terms
#include<stdio.h> #include<conio.h> void main() { int c=1,i; unsigned int s=0; clrscr(); for(i=1,(i<=15;i++)) { if(i%2==0) { s=s+i; c=c+i; } } printf("/n sum of the first 15 even numbers is%d",s); printf("/n square of the sum is: %d",(s*s)); getch(); }
main() { int i, n, sum=0; cout<<"Enter the limit"; cin>>n; for(i=0;i<=n;i++) sum=sum+i; cout<<"sum of "<<n<<" natural numbers ="<<sum; getch(); }
int SumOfDigits (int N) { int sum; if (N < 0) N = -N; for (sum = 0; N != 0; N /= 10) sum += N % 10; return sum; }
#include<stdio.h> #include<conio.h> main() { int n,sum=0; printf("enter n value"); scanf("%d",n); while(n!=0) { n=n/10; sum=sum+n; n=n%10; } printf("sum is=%d",sum }
#include <stdio.h> #include<conio.h> void main () { int a,r,n,sum=0; clrscr(); printf("enter the number"); scanf("%d",& n); c=n while (n!=0) { a=n%10; n=n/10; sum=sum*a+a } printf("the reverse is %d \n",sum); if(c==sum) printf("\n the given number is palindrome"); else printf("\n the given number is not a palindrome"); getch(); }
int sum (int n) { if (n<=1) return n; else return n + sum (n-1); }
if (n%2==0) sum=n/2*(n+1); else sum=(n+1)/2*n;
for (n=1; n<1000; ++n) { for (sum=0, k=1; k<=n/2; ++k) if (n%k==0) sum += k; if (sum==n) printf ("%d\n", n); }
void main () { int no1, sum, n; clrscr() sum = 0; n = 1; printf("\n enter the number to which sum is to be generated"); scanf("%d",&no1); while(n<=no1) { sum=sum+n; n=n+1 } printf("\n the sum of %d = %d, no1, sum"); getch (); }
#include<stdio.h> #include<conio.h> main() { int sum_sqr(int n); printf("%d",sum_sqr(5)); printf("\n"); getch(); } int sum_sqr(int n) { int i,sum=0; for(i=1;i<=n;i++) { sum=sum+(i*i); } return sum; }
#include<stdio.h> void main() { long long int sum=0,n,i,b; printf("How many numbers do you want to add?\n"); scanf("%lld",&n); printf("Enter those %lld numbers\n",n); for(i=0;i<n;i++) { scanf("%lld",&b); sum=sum+b; } printf("Sum of all the numbers you entered is %lld",sum); getch(); }
#include #define NUM 100 //since prog is to be written for adding 100 naturalint main(){int i,sum=0;for(i=1;i
main(){int n,a[i],s;s=0;printf("enter no of elements in array");scanf("%d",&n);printf("Enter elements in array");for(i=;i