C Program for the cube sum of first n natural numbers?


The cube sum of first n natural numbers is the program to add cubes of all natural numbers up to n. It is sum of series 1^3 + 2^3 + …. + n^3 that is sum of cube of n natural numbers.

Input:6
Output:441

Explanation

1^3 + 2^3 + 3^3 + 4^3 + 5^3 + 63 = 441

Using For loop to increase the no. and cubing it and taking sum of them.

Example

#include <iostream>
using namespace std;
int main() {
   int n = 6;
   int sum = 0;
   for (int i = 1; i <= n; i++) {
      sum += i * i * i;
   }
   printf(“%d”, sum);
   return 0;
}

Updated on: 19-Aug-2019

452 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements