Find the sum of n terms of the series 1,8,27,64 ….
Given a series, the task is to find the sum of the below series up to n terms:
1, 8, 27, 64, …
Examples:
Input: N = 2 Output: 9 9 = (2*(2+1)/2)^2 Input: N = 4 Output: 100 100 = (4*(4+1)/2)^2
Approach: We can solve this problem using the following formula:
Sn = 1 + 8 + 27 + 64 + .........up to n terms
Sn = (n*(n+1)/2)^2
Below is the implementation opf above approach:
C++
// C++ program to find the sum of n terms #include <bits/stdc++.h> using namespace std; // Function to calculate the sum int calculateSum(int n) { // Return total sum return pow(n * (n + 1) / 2, 2); } // Driver code int main() { int n = 4; cout << calculateSum(n); return 0; } |
chevron_right
filter_none
Java
// Java program to find the sum of n terms import java.io.*; class GFG { // Function to calculate the sum static int calculateSum(int n) { // Return total sum return (int)Math.pow(n * (n + 1) / 2, 2); } // Driver code public static void main (String[] args) { int n = 4; System.out.println( calculateSum(n)); } } // This code is contributed by inder_verma.. |
chevron_right
filter_none
Python3
# Python3 program to find the # sum of n terms #Function to calculate the sum def calculateSum(n): #return total sum return (n * (n + 1) / 2)**2 #Driver code if __name__=='__main__': n = 4 print(calculateSum(n)) #this code is contributed by Shashank_Sharma |
chevron_right
filter_none
C#
// C# program to find the sum of n terms using System; class GFG { // Function ot calculate the sum static int calculateSum(int n) { // Return total sum return (int)Math.Pow(n * (n + 1) / 2, 2); } // Driver code public static void Main () { int n = 4; Console.WriteLine(calculateSum(n)); } } // This code is contributed // by Akanksha Rai(Abby_akku) |
chevron_right
filter_none
PHP
<?php // PHP program to find // the sum of n terms // Function to calculate the sum function calculateSum($n) { // Return total sum return pow($n * ($n + 1) / 2 , 2); } // Driver code $n = 4; echo calculateSum($n); // This code is contributed // by ANKITRAI1 ?> |
chevron_right
filter_none
Output:
100
Recommended Posts:
- Find n terms of Fibonacci type series with given first two terms
- Find the sum of first N terms of the series 2*3*5, 3*5*7, 4*7*9, ...
- Find the sum of all the terms in the n-th row of the given series
- Find the sum of first N terms of the series 2×3 + 4×4 + 6×5 + 8×6 + ...
- Find the sum of series 0.X + 0.XX + 0.XXX +... upto k terms
- Find the sum of series 3, -6, 12, -24 . . . upto N terms
- Find sum of the series ?3 + ?12 +......... upto N terms
- Find Sum of Series 1^2 - 2^2 + 3^2 - 4^2 ..... upto n terms
- Find sum of the series 1+22+333+4444+...... upto n terms
- Find the sum of the series 1+11+111+1111+..... upto n terms
- Program to find the sum of the series 23+ 45+ 75+..... upto N terms
- Sum of first n terms of a given series 3, 6, 11, .....
- Sum of the first N terms of the series 5,12, 23, 38....
- Sum of the first N terms of the series 2,10, 30, 68,....
- Sum of the series 5+55+555+.. up to n terms
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



