Write a code to get the summation of the 'n' series - C PROGRAMMING LANGUAGE @

C PROGRAMMING LANGUAGE @

LEARN TODAY LEAD TOMORROW

Thursday, July 6, 2017

Write a code to get the summation of the 'n' series

Write a code to get the summation of the following series:
1 + 2 + 4 + 7 + ………… + n terms.

                                                                   
Algorithm:
procedure()
sum=0;
for i=0 to n;
sum=sum+((i*i+i+2)/2);
end procedure;

source code:
#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("Enter the number: ");
scanf("%d",&n); //assign the value of n is 3
for(i=0;i<=n;i++)
{
sum=sum+((i*i+i+2)/2);
}
printf("Sum is %d.\n",sum);
}


output:
sum is 14.
                                                                           

No comments:

Post a Comment