C Program to Find Sum of series 1³+2³+3³+….+n³

In this tutorial, i am going to show you how to find sum of series 1³+2³+3³+….+n³ with the help of a standard formula, for loop, function, and recursion in c programs.

All C Programs to Find Sum of series 1³+2³+3³+….+n³

  • C Program to Find Sum of series 1³+2³+3³+….+n³ using Standard Formula
  • C Program to Find Sum of series 1³+2³+3³+….+n³ using For Loop
  • C Program to Find Sum of series 1³+2³+3³+….+n³ using Function
  • C Program to Find Sum of series 1³+2³+3³+….+n³ using Recursion

C Program to Find Sum of series 1³+2³+3³+….+n³ using Standard Formula

/* Sum of Cubes of n Natural Numbers */
#include <stdio.h>
#include <math.h>
int main()
{
  int Number, Sum = 0;
  printf("\n Please Enter any positive integer \n");
  scanf(" %d",&Number);
  Sum = pow(((Number * (Number + 1))/ 2), 2);
 
  printf("\n The Sum of Series for %d = %d ",Number, Sum);
}

The result of the above c program; is as follows:

Please Enter any positive integer 
10
The Sum of Series for 10 = 3025 

C Program to Find Sum of series 1³+2³+3³+….+n³ using For Loop

/* Sum of Cubes of n Natural Numbers */
#include <stdio.h>
#include <math.h>
int main()
{
  int Number, i, Sum = 0;
  printf("\nPlease Enter any positive integer \n");
  scanf("%d",&Number);
  Sum = pow(((Number * (Number + 1))/ 2), 2);
  
  for(i =1; i<=Number;i++)
  {
    if (i != Number)
       printf("%d^3 + ",i);
    
    else
       printf("%d^3 = %d ",i, Sum);
  }
}

The result of the above c program; is as follows:

Please Enter any positive integer 
5
1^3 + 2^3 + 3^3 + 4^3 + 5^3 = 225 

C Program to Find Sum of series 1³+2³+3³+….+n³ using Function

/* Sum of Cubes of n Natural Numbers */
#include <stdio.h>
#include <math.h>
void Sum_Of_Series(int);
int main()
{
  int Number;
  printf("\n Please Enter any positive integer \n");
  scanf("%d",&Number);
  Sum_Of_Series(Number);
}
void Sum_Of_Series(int Number)
{
  int i, Sum = 0;
  Sum = pow (((Number * (Number + 1))/ 2), 2);;
  
  for(i =1;i<=Number;i++)
  {
   if (i != Number)
     printf("%d^3  + ",i);
   else
     printf(" %d^3 = %d ", i, Sum); 
  } 
}

The result of the above c program; is as follows:

Please Enter any positive integer 
5
1^3  + 2^3  + 3^3  + 4^3  +  5^3 = 225 

C Program to Find Sum of series 1³+2³+3³+….+n³ using Recursion

/* Sum of Cubes of n Natural Numbers */
#include <stdio.h> 
int Sum_Of_Series(int);
int main()
{
  int Number, Sum;
  printf("\nPlease Enter any positive integer \n");
  scanf("%d",&Number);
  Sum =Sum_Of_Series(Number);
  printf("\nSum of the Series  = %d",Sum);
}
int Sum_Of_Series(int Number)
{
  if(Number == 0)
    return 0;
  
  else      
    //Recursive Calling   
    return (Number * Number * Number) + Sum_Of_Series(Number-1);  
}

The result of the above c program; is as follows:

Please Enter any positive integer 
10
Sum of the Series  = 3025

More C Programming Tutorials

Leave a Comment