Write a code to get the summation of the following N series: - C PROGRAMMING LANGUAGE @

C PROGRAMMING LANGUAGE @

LEARN TODAY LEAD TOMORROW

Friday, July 7, 2017

Write a code to get the summation of the following N series:

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

                                                                 
                                                                     
Algorithm:
procedure()
sum=0;
for i=1 to n;
sum=sum+(i*i);
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 5
for(i=1;i<=n;i++)
{
sum=sum+(i*i);
}
printf("Sum is %d.\n",sum);
return 0;
}
output:
sum is 55.                                                                              
   

No comments:

Post a Comment