📌  相关文章
📜  级数之和 0.7, 0.77, 0.777, ... 最多 n 项

📅  最后修改于: 2022-05-13 01:57:58.956000             🧑  作者: Mango

级数之和 0.7, 0.77, 0.777, ... 最多 n 项

给定 n 项数。求系列 0.7, 0.77, 0.777, ... 最多 n 项的总和。
例子 :

Input : 2
Output : 1.46286

Input : 3
Output : 2.23609

使用的方法:
让我们用 S 表示系列的总和:

以下是查找给定系列总和的实现:

C++
// C++ program for sum of the series 0.7,
// 0.77, 0.777, ... upto n terms
#include 
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 = 2
print(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


Javascript


输出:

1.46286