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

C PROGRAMMING LANGUAGE @

LEARN TODAY LEAD TOMORROW

Saturday, July 8, 2017

Write a code to get the summation of the n^3 series

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

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

No comments:

Post a Comment