Computer Applications
Write the program in Java to find the sum of the following series:
S = 1 + (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + ……. + (1 + 2 + 3 ……. + n) / (1 * 2 * 3 * ……. * n)
Java
Java Iterative Stmts
ICSE 2007
21 Likes
Answer
import java.util.Scanner;
public class KboatSeries
{
public void computeSeriesSum() {
Scanner in = new Scanner(System.in);
System.out.print("Enter n: ");
int n = in.nextInt();
double seriesSum = 0.0;
int sum = 0;
double prod = 1.0;
for (int i = 1; i <= n; i++) {
sum += i;
prod *= i;
double term = sum / prod;
seriesSum += term;
}
System.out.println("Sum=" + seriesSum);
}
}
Variable Description Table
Program Explanation
Output
Answered By
12 Likes
Related Questions
Write the program in Java to find the sum of the following series:
S = 1 + (1+2) + (1+2+3) + ……. + (1+2+3+ ……. + n)
Write the program to find the sum of the following series:
S = (a+1) + (a+2) + (a+3) + ……. + (a+n)
Write the program in Java to find the sum of the following series:
S = 1 + (1*2) + (1*2*3) + ……. + (1*2*3* ……. * n)
Write the program to find the sum of the following series:
S = a + a2 + a3 + ……. + an