Computer Science, asked by JoyeetaDas, 10 months ago

write a program to find the series 2 12 30 56...n in java​

Answers

Answered by livegamer63p
0

Answer:

Input: N = 2

Output: 8

2 + 6

= 8

Input: N = 4

Output: 40

2 + 6+ 12 + 20

= 40C++ program to find sum of first n terms

#include <bits/stdc++.h>

using namespace std;

// Function to calculate the sum

int calculateSum(int n)

{

return n * (n + 1) / 2 + n *

(n + 1) * (2 * n + 1) / 6;

}

// Driver code

int main()

{

// number of terms to be

// included in the sum

int n = 3;

// find the Sn

cout << "Sum = " << calculateSum(n);

return 0;

}

Answered by rocky7890
0

Answer:

40

Explanation:

Input: N = 2

Output: 8

2 + 6

= 8

Input: N = 4  

Output: 40

2 + 6+ 12 + 20

= 40

Similar questions