Sum = n/2[2Xa1+(n-1)d] where n is last number, a1 is the first number & d is the common difference between the numbers, here d=2 for the even /odd numbers. Sum = n/2 [2Xa1+(n-1)2]
#include #define NUM 100 //since prog is to be written for adding 100 naturalint main(){int i,sum=0;for(i=1;i
For the first 5 natural numbers (integers):x = 1 + 2 + 3 + 4 + 5print xFor 'n' amount of natural numbers (Python v2 example)n = int(raw_input('Enter max integer: '))count = 0sumn = 0while count < n:sumn = sumn + 1count = count + 1print sumn
to print the sum of first ten numbers:- void main() {int i,sum; sum=0; while(i<=10) sum=sum+i; i=i+1; } printf("The sum is : %d",sum); }
#include#includevoid main(){int sum_sqr(int n);clrscr();printf("%d",sum_sqr(5));//Sum of first 5 natural numbers' square valuesgetch();}int sum_sqr(int n){int i,sum=0;for(i=1;i
1 Sum of first n natural numbers = n(n+1)2[Formula.]2 Arthmetic mean of first n natural numbers = Sum of the numbers n[Formula.]3 = n(n+1)2n = n+124 So, the Arthmetic mean of first n natural numbers = n+12
The sum of the first n natural numbers is n*(n+1)/2 There are n numbers so their mean = (n+1)/2
Formula for sum of first natural number = n(n+1)/2 , here n=225 so, answer is 225(225+1)/2 = 25425
The sum of the first N square numbers is: N*(N+1)*(2N+1)/6 So putting N = 20 gives 2870.
Sum of first n natural numbers is (n) x (n + 1)/2 Here we have the sum = 100 x (101)/2 = 50 x 101 = 5050
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(); }
Mean = (sum of the n numbers)/n
The sum of the first n cubed numbers is: [n*(n+1)/2]2 which is the same as the square of the sum of the first n numbers.
sum of n natural number is n(n+1)/2 first 50 number sum is 50(50+1)/2 = 1275
Algorithm to find the sum of first n natural numbers:1. Read n.2. Initialize N=1.3. Initialize sum S=0.4. Calculate S=S+N.5. Calculate N=N+1.6. If N>n, then goto step 7 else goto step 4.7. Write the sum S.8. Stop.
The sum of the first "n" numbers is equal to n(n+1)/2.
n*(n+1)