📌  相关文章
📜  系列 8/10、8/100、8/1000、8/10000 的总和。 . .直到 N 项

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

系列 8/10、8/100、8/1000、8/10000 的总和。 . .直到 N 项

给定一个正整数n ,任务是找到序列的和

例子:

方法:

给定 GP 系列的第 n项的总和可以概括为-

上述公式可以通过以下一系列步骤推导出来——

插图:

下面是上述问题的实现——

C++
// C++ program to implement
// the above approach
#include 
using namespace std;
 
// Function to calculate sum of
// given series till Nth term
double sumOfSeries(double N)
{
    return (8 * ((pow(10, N) - 1) / pow(10, N))) / 9;
}
 
// Driver code
int main()
{
    double N = 5;
    cout << sumOfSeries(N);
    return 0;
}


Java
// Java program to implement
// the above approach
import java.util.*;
public class GFG
{
   
    // Function to calculate sum of
    // given series till Nth term
    static double sumOfSeries(double N)
    {
        return (8
                * ((Math.pow(10, N) - 1) / Math.pow(10, N)))
            / 9;
    }
 
    // Driver code
    public static void main(String args[])
    {
        double N = 5;
        System.out.print(sumOfSeries(N));
    }
}
 
// This code is contributed by Samim Hossain Mondal.


Python3
# Python code for the above approach
 
# Function to calculate sum of
# given series till Nth term
def sumOfSeries(N):
    return (8 * (((10 ** N) - 1) / (10 ** N))) / 9;
 
# Driver code
N = 5;
print(sumOfSeries(N));
 
# This code is contributed by gfgking


C#
// C# program to implement
// the above approach
using System;
class GFG
{
   
    // Function to calculate sum of
    // given series till Nth term
    static double sumOfSeries(double N)
    {
        return (8
                * ((Math.Pow(10, N) - 1) / Math.Pow(10, N)))
            / 9;
    }
 
    // Driver code
    public static void Main()
    {
        double N = 5;
        Console.WriteLine(sumOfSeries(N));
    }
}
 
// This code is contributed by ukasp.


Javascript


输出
0.88888

时间复杂度: O(1)
辅助空间: O(1)