programming-examples/c/Series_Programs/C Program to find Sum of cube of n natural numbers.c

20 lines
449 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
/* Sum of cube of n natural numbers.*/
#include<stdio.h>
#include<math.h>
main()
{
int n,i;
int sum=0;
printf("Enter the n i.e. max values of series: ");
scanf("%d",&n);
sum = pow(((n * (n + 1) ) / 2),2);
printf("Sum of the series : ");
for(i =1; i<=n; i++)
{
if (i != n)
printf("%d^3 + ",i);
else
printf("%d^3 = %d ",i,sum);
}
}