Sum of the series 0.7, 0.77, 0.777, … upto n terms
Given n the number of terms. Find the sum of the series 0.7, 0.77, 0.777, … upto n terms.
Examples :
Input : 2 Output : 1.46286 Input : 3 Output : 2.23609
Approach Used :
Let’s denote the sum of the series by S:
Sum = 0.7 + 0.77 + 0.777 + …. up to n terms
= 7/9(0.9 + 0.99 + 0.999 + … up to n terms)
= 7/9[(1 – 0.1) + (1 – 0.01) + (1-0.001) + … up to n terms]
= 7/9[(1 + 1 + 1… upto n terms) – (1/10 + 1/100 + 1/1000 + … upto n terms)]
= 7/9[n – 0.1 * (1 – (0.1)n)/(1 – 0.1)]
= 7/81[9n – 1 + 10-n]
Below is the Implementation to find the sum of given series:
C++
// C++ program for sum of the series 0.7, // 0.77, 0.777, ... upto n terms #include <bits/stdc++.h> using namespace std; // function which return the // the sum of series float sumOfSeries(int n) { return .086 * (9 * n - 1 + pow(10, (-1) * n)); } // Driver code int main() { int n = 2; cout << sumOfSeries(n); return 0; } |
Java
// Java program for sum of the series 0.7, // 0.77, 0.777, ... upto n terms import java.io.*; import java.math.*; class GFG { // function which return the // the sum of series static float sumOfSeries(int n) { return .086f * (9 * n - 1 + (float)(Math.pow(10, (-1) * n))); } // Driver code public static void main(String args[]) { int n = 2; System.out.println(sumOfSeries(n)); } } /*This code is contributed by Nikita Tiwari.*/ |
Python3
# Python 3 program for sum of the series 0.7, # 0.77, 0.777, ... upto n terms import math # Function which return the # the sum of series def sumOfSeries(n) : return .086 * (9 * n - 1 + math.pow(10, (-1) * n)); # Driver code n = 2print(sumOfSeries(n)) # This code is contributed by Nikita Tiwari. |
C#
// C# program for sum of the series // 0.7, 0.77, 0.777, ... upto n terms using System; class GFG { // Function which return the // the sum of series static float sumOfSeries(int n) { return .086f * (9 * n - 1 + (float)(Math.Pow(10, (-1) * n))); } // Driver code public static void Main() { int n = 2; Console.Write(sumOfSeries(n)); } } // This code is contributed by vt_m. |
PHP
<?php // PHP program for sum of the series // 0.7, 0.77, 0.777, ... upto n terms // function which return the // the sum of series function sumOfSeries($n) { return .086 * (9 * $n - 1 + pow(10, (-1) * $n)); } // Driver code $n = 2; echo(sumOfSeries($n)); // This code is contributed by Ajit. ?> |
Output :
1.46286
Recommended Posts:
- 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 (1*2) + (2*3) + (3*4) + ...... upto n terms
- Find the sum of series 0.X + 0.XX + 0.XXX +... upto k 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 the sum of series 3, -6, 12, -24 . . . 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
- Find sum of the series 1+22+333+4444+...... upto n terms
- Find n terms of Fibonacci type series with given first two terms
- Sum of the Tan(x) expansion upto N terms
- Program to get the Sum of series: 1 - x^2/2! + x^4/4! -.... upto nth term
- Sum of the first N terms of the series 2,10, 30, 68,....
- Sum of the first N terms of the series 5,12, 23, 38....
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



