Computer Applications

Write a program to find the sum of the given series:

S = (2/3) + (4/5) + (8/7) + --------- to n terms.

Java

Java Iterative Stmts

22 Likes

Answer

import java.util.Scanner;

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

Variable Description Table

Program Explanation

Output

Answered By

12 Likes


Related Questions