The sum of n and 5 is n+ 5
#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 }
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 (); }
int sum (int n){if (n
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; }
Sum = 0 For N = 1 to 10 Sum = Sum + 2*N Next N Print Sum
sum = 0 for(n = 0; n <= 10; n += 2) sum += n;
int sum(n) { if (n==0) return 0; else return n+sum(n-1); }
its 5035the summarian notation tells you that(sum of all #from 0 to a number'N'(sum of all #from 0 to N) = (n)+(n-1)+(n-2)+(n-3)+...+(2) +(1) or(sum of all #from 0 to N) = (1)+ (2) + (3) + (4)+...+(n-1)+(n)the two different sums are aligned by columns. now add the two colunms accordingly and you'll get2x(sum of all #from 0 to N)=(n+1)+(n+1)+...+(n+1) (n+1)is added n timesso2x(sum of all #from 0 to N) =n(n+1)(sum of all #from 0 to N) =n(n+1)/2so (sum of 5 to 100) = (sum of 0 to 100)- (sum of 0 to 5)=100(101)/2 - 5(6)/2 = 5050 - 15 = 5035
The sum of any integer ( n ) and zero is ( n ).
n + (8 + 6)