This C Program calculates the Sum of Series 1^3 + 2^3 + 3^3 + … + n^3. Sum of the series 1^3 + 2^3 + 3^3 + … + n^3 = (n(n + 1) / 2)2
Here is source code of the C Program to Find the Sum of Series 1^3 + 2^3 + 3^3 + … + n^3. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Find the Sum of Series 1^3 + 2^3 + 3^3 + … + n^3
*/
#include <stdio.h>
#include <math.h>
int main()
{
int number, i;
int sum = 0;
printf("Enter the maximum values of series n: ");
scanf("%d", &number);
sum = pow(((number * (number + 1) ) / 2),2);
printf("Sum of the series : ");
for (i = 1; i <= number; i++)
{
if (i != number)
printf("%d^3 + ", i);
else
printf("%d^3 = %d ", i, sum);
}
return 0;
}
Output: $ cc pgm17.c $ a.out Enter the maximum values of series n: 5 Sum of the series : 1^3 + 2^3 + 3^3 + 4^3 + 5^3 = 225
Related Posts:
- Check C Books
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Practice BCA MCQs
- Apply for C Internship