Find sum of the series 1+22+333+4444+…… upto n terms
Given a number N. The task is to find the sum of the below series up to N-th term:
1 + 22 + 333 + 4444 + …up to n terms
Examples:
Input: N = 3 Output: 356 Input: N = 10 Output: 12208504795
Approach:

Below is the implementation of the above approach:
C++
// CPP program to find the sum // of given series #include <iostream> #include <math.h> using namespace std; // Function to calculate sum int findSum(int n) { // Return sum return (pow(10, n + 1) * (9 * n - 1) + 10) / pow(9, 3) - n * (n + 1) / 18; } // Driver code int main() { int n = 3; cout << findSum(n); return 0; } |
chevron_right
filter_none
Java
// Java Program to find // Sum of first n terms import java.util.*; class solution { static int calculateSum(int n) { // Returning the final sum return ((int)Math.pow(10, n + 1) * (9 * n - 1) + 10) / (int)Math.pow(9, 3) - n * (n + 1) / 18; } // Driver code public static void main(String ar[]) { // no. of terms to find the sum int n=3; System.out.println("Sum= "+ calculateSum(n)); } } //This code is contributed by Surendra_Gangwar |
chevron_right
filter_none
Python 3
# Python program to find the sum of given series. # Function to calculate sum def solve_sum(n): # Return sum return (pow(10, n + 1)*(9 * n - 1)+10)/pow(9, 3)-n*(n + 1)/18 # driver code n = 3 print(int(solve_sum(n))) |
chevron_right
filter_none
C#
// C# Program to find // Sum of first n terms using System; class solution { static int calculateSum(int n) { // Returning the final sum return ((int)Math.Pow(10, n + 1) * (9 * n - 1) + 10) / (int)Math.Pow(9, 3) - n * (n + 1) / 18; } // Driver code public static void Main() { // no. of terms to find the sum int n=3; Console.WriteLine("Sum= "+ calculateSum(n)); } } //This code is contributed by inder_verma. |
chevron_right
filter_none
PHP
<?php // PHP program to find the sum // of given series // Function to calculate sum function findSum($n) { // Return sum return (pow(10, $n + 1) * (9 * $n - 1) + 10) / pow(9, 3) - $n * ($n + 1) / 18; } // Driver code $n = 3; echo findSum($n); // This code is contributed // by inder_verma. ?> |
chevron_right
filter_none
Output:
356
Recommended Posts:
- Find Sum of Series 1^2 - 2^2 + 3^2 - 4^2 ..... upto n terms
- Find sum of the series ?3 + ?12 +......... upto N terms
- Find the sum of series 3, -6, 12, -24 . . . upto N terms
- Find the sum of series 0.X + 0.XX + 0.XXX +... upto k terms
- Program to find the sum of the series 23+ 45+ 75+..... upto N terms
- Find the sum of the series 1+11+111+1111+..... upto n terms
- Sum of series 2/3 - 4/5 + 6/7 - 8/9 + ------- upto n terms
- Sum of the series 1 / 1 + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + - - - - - - upto n terms.
- Sum of the series 0.7, 0.77, 0.777, ... upto n terms
- Sum of the series (1*2) + (2*3) + (3*4) + ...... upto n terms
- Find n terms of Fibonacci type series with given first two terms
- Find the sum of n terms of the series 1,8,27,64 ....
- Find the sum of first N terms of the series 2*3*5, 3*5*7, 4*7*9, ...
- Find the sum of first N terms of the series 2×3 + 4×4 + 6×5 + 8×6 + ...
- Find the sum of all the terms in the n-th row of the given series
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.



