KnowledgeBoat Logo

Computer Applications

Write a program to find the sum of first 20 terms of the series:

S = (2/3) + (4/5) + (8/7) + (16/9) + ----------

Java

Java Iterative Stmts

36 Likes

Answer

public class KboatSeriesSum
{
    public static void main(String args[]) {
        double sum = 0.0;
        for (int i = 1, j = 3; i <= 20; i++, j += 2) {
            sum += Math.pow(2, i) / j;
        }
        System.out.println("Sum = " + sum);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program to find the sum of first 20 terms of the series: S = (2/3) + (4/5) + (8/7) + (16/9) + ----------

Answered By

17 Likes


Related Questions