Monday, August 20, 2018

CUBE SERIES

  • Problem Description

    Your task is to write a code to find the sum of the following series
    13 + 23 + 33 + + n3
    Input:
    Input should contain the value of the limit n
    Output:
    It should print the Sum of series upto n limit

  • CODING ARENA::
  • #include<stdio.h>
    #include<math.h>
    int main() {
    int n,i;
    int sum=0;
    scanf("%d",&n);
    sum = pow(((n * (n + 1) ) / 2),2);
    for (i =1;i<=n;i++)
        {
    if (i != n)
                 printf("%d^3 + ",i); 
          else
                 printf("%d^3=%d",i,sum);
    }
    return 0;
    }
      
  • Test Case 1

    Input (stdin)
    2
    
    
    Expected Output
    1^3 + 2^3=9
  • Test Case 2

    Input (stdin)
    3
    
    
    Expected Output
    1^3 + 2^3 + 3^3=36

No comments:

Post a Comment