Related Articles

# Sum of the series 0.6, 0.06, 0.006, 0.0006, …to n terms

• Last Updated : 19 Mar, 2021

Given the number of terms i.e. n. Find the sum of the series 0.6, 0.06, 0.006, 0.0006, …to n terms.
Examples:

Input : 2
Output : 0.65934

Input : 3
Output : 0.665334

Attention reader! All those who say programming isn't for kids, just haven't met the right mentors yet. Join the  Demo Class for First Step to Coding Coursespecifically designed for students of class 8 to 12.

The students will get to learn more about the world of programming in these free classes which will definitely help them in making a wise career choice in the future.

Lets denote the sum by S:
Using the formula , we have [since r<1]   Hence the required sum is Below is the implementation:

## C++

 // CPP program to find sum of 0.6, 0.06,// 0.006, 0.0006, ...to n terms#include using namespace std; // function which return the// the sum of seriesfloat sumOfSeries(int n){    return (0.666) * (1 - 1 / pow(10, n));} // Driver codeint main(){    int n = 2;    cout << sumOfSeries(n);}

## Java

 // java program to find sum of 0.6, 0.06,// 0.006, 0.0006, ...to n termsimport java.io.*; class GFG{    // function which return the    // the sum of series    static double sumOfSeries(int n)    {        return (0.666) * (1 - 1 /Math. pow(10, n));    }              // Driver code    public static void main (String[] args)    {        int n = 2;        System.out.println ( sumOfSeries(n));             }} // This code is contributed by vt_m

## Python3

 # Python3 program to find# sum of 0.6, 0.06, 0.006,# 0.0006, ...to n termsimport math # function which return# the sum of seriesdef sumOfSeries(n):    return ((0.666) *            (1 - 1 / pow(10, n))); # Driver coden = 2;print(sumOfSeries(n)); # This code is contributed by mits

## C#

 // C# program to find sum of 0.6, 0.06,// 0.006, 0.0006, ...to n termsusing System; class GFG {         // function which return the    // the sum of series    static double sumOfSeries(int n)    {        return (0.666) * (1 - 1 /Math. Pow(10, n));    }         // Driver code    public static void Main ()    {        int n = 2;                 Console.WriteLine( sumOfSeries(n));             }} // This code is contributed by vt_m

## PHP

 

## Javascript

 

Output:

0.65934

My Personal Notes arrow_drop_up