Logic:
- Enter the number n
- sum= 13 + 23+ 33 + 43+……..+n3
Algorithm
- Enter the number as n
- Initially assign sum=0
- for(i=1;i<=n;i++)
- sum=sum + i * i * i;
- Print sum
Program
#include<stdio.h>
void main()
{
printf("***************************************************************");
printf("\n****************************************************************");
printf("\n** WAP to print sum of cubes of first n natural numbers **");
printf("\n** Created by Sheetal Garg **");
printf("\n** Assistant Professor **");
printf("\n** Phone No:9467863365 **");
printf("\n****************************************************************");
printf("\n****************************************************************\n");
int i,n,s=0;
printf("Enter number upto which cube you want to add");
scanf("%d",&n);
for(i=1;i<=n;i++)
s= s + i * i * i;
printf("sum is %d",s);
}
Output 1
*************************************************************** **************************************************************** ** WAP to print sum of cubes of first n natural numbers ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** **************************************************************** **************************************************************** Enter number upto which cube you want to add 3 sum is 36