# Sum of the sequence 2, 22, 222, ………

Find the sum of the following sequence : 2, 22, 222, ……… to n terms.
Examples :

```Input : 2
Output: 1.9926

Input : 3
Output: 23.9112
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

A simple solution is to compute terms one by one and add to the result.

The above problem can be efficiently solved using the following formula:

## C++

 `// CPP program to find sum of series ` `// 2, 22, 222, .. ` `#include ` `using` `namespace` `std; ` ` `  `// function which return the ` `// the sum of series ` `float` `sumOfSeries(``int` `n) ` `{ ` `    ``return` `0.0246 * (``pow``(10, n) - 1 - (9 * n)); ` `} ` ` `  `// driver code ` `int` `main() ` `{ ` `    ``int` `n = 3; ` `    ``cout << sumOfSeries(n); ` `    ``return` `0; ` `} `

## Java

 `// JAVA Code for Sum of the ` `// sequence 2, 22, 222,... ` `import` `java.util.*; ` ` `  `class` `GFG { ` `     `  `    ``// function which return the ` `    ``// the sum of series ` `    ``static` `double` `sumOfSeries(``int` `n) ` `    ``{ ` `        ``return` `0.0246` `* (Math.pow(``10``, n) ` `                            ``- ``1` `- (``9` `* n)); ` `    ``} ` `     `  `    ``/* Driver program */` `    ``public` `static` `void` `main(String[] args)  ` `    ``{ ` `         ``int` `n = ``3``; ` `         ``System.out.println(sumOfSeries(n)); ` `    ``} ` `} ` ` `  `// This code is contributed by Arnav Kr. Mandal. `

## Python3

 `# Python3 code to find  ` `# sum of series ` `# 2, 22, 222, .. ` `import` `math ` ` `  `# function which return  ` `# the sum of series ` `def` `sumOfSeries( n ): ` `    ``return` `0.0246` `*` `(math.``pow``(``10``, n) ``-` `1` `-` `(``9` `*` `n)) ` `     `  `# driver code ` `n ``=` `3` `print``( sumOfSeries(n)) ` ` `  `# This code is contributed by "Sharad_Bhardwaj". `

## C#

 `// C# Code for Sum of the ` `// sequence 2, 22, 222,... ` `using` `System; ` ` `  `class` `GFG { ` `     `  `    ``// Function which return the ` `    ``// the sum of series ` `    ``static` `double` `sumOfSeries(``int` `n) ` `    ``{ ` `        ``return` `0.0246 * (Math.Pow(10, n) ` `                           ``- 1 - (9 * n)); ` `    ``} ` `     `  `    ``// Driver Code ` `    ``public` `static` `void` `Main()  ` `    ``{ ` `        ``int` `n = 3; ` `        ``Console.Write(sumOfSeries(n)); ` `    ``} ` `} ` ` `  `// This code is contributed by vt_m. `

## PHP

 ` `

Output :

```23.9112
```

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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.

Improved By : jit_t

Article Tags :
Practice Tags :

1

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.