Computer Science, asked by suvamtalukder2002, 11 months ago

Write a C++ program to calculate cube of first 15 even numbers.

Answers

Answered by Anonymous
1

The efficient approach is discussed below


The sum of cubes of first n natural numbers is given by = (n*(n+1) / 2)^2


Sum of cubes of first n natural numbers can be written as...

= 2^3 + 4^3 + .... + (2n)^3


Now take out common term i.e 2^3

= 2^3 * (1^3 + 2^3 + .... + n^3)

= 2^3* (n*(n+1) / 2)^2

= 8 * ((n^2)(n+1)^2)/4

= 2 * n^2(n+1)^2


#include <iostream>

using namespace std;


int calculate(int n)

{

int sum = 2 * n * n * (n + 1) * (n + 1);

return sum;

}


int main()

{

int num = 15;

cout<<"Number is = "<<num<<endl;

cout << "Sum of cubes of first "<<num<<" even number is ="<<calculate(num);

return 0;

}

Answered by aishu0105
2

Answer:

Answer:

#include <iostream>

using namespace std;

int calculate(int n)

{

int sum = 2 * n * n * (n + 1) * (n + 1);

return sum;

}

int main()

{

int num = 15;

cout<<"Number is = "<<num<<endl;

cout << "Sum of cubes of first "<<num<<" even number is ="<<calculate(num);

return 0;

}

hope it helps u...

follow me !!

plzz mark as brainliest

Similar questions