C Program to Find Sum of Series 1^3 + 2^3 + 3^3 + … + n^3

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.

  1. /*
  2.  * C Program to Find the Sum of Series 1^3 + 2^3 + 3^3 + … + n^3
  3.  */
  4. #include <stdio.h>
  5. #include <math.h>
  6.  
  7. int main()
  8. {
  9.     int number, i;
  10.     int sum = 0;
  11.  
  12.     printf("Enter the maximum values of series n: ");
  13.     scanf("%d", &number);
  14.     sum = pow(((number * (number + 1) ) / 2),2);
  15.     printf("Sum of the series : ");
  16.     for (i = 1; i <= number; i++)
  17.     {
  18.         if (i != number)
  19.             printf("%d^3 + ", i);
  20.         else
  21.             printf("%d^3 = %d ", i, sum);
  22.     }
  23.     return 0;
  24. }

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

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.