Computer Applications
Write a program in Java to find the sum of the following series:
S = 1 + (3/2!) + (5/3!) + (7/4!) + ……. to n
Answer
import java.util.Scanner;
public class KboatSeries
{
public void computeSum() {
Scanner in = new Scanner(System.in);
System.out.print("Enter n: ");
int n = in.nextInt();
double sum = 0.0;
for (int i = 1, j = 1; i <= n; i++, j = j + 2) {
double f = 1;
for (int k = 1; k <= i; k++) {
f *= k;
}
sum += j / f;
}
System.out.println("Sum=" + sum);
}
}
Variable Description Table
Program Explanation
Output
Related Questions
Write a program in Java to find the sum of the following series:
S = a + (a/2!) + (a/3!) + (a/4!) + ……. + (a/n!)
Write a program in Java to find the sum of the following series:
S = (a/2!) - (a/3!) + (a/4!) - (a/5!) + ……. + (a/10!)
Write a program in Java to find the sum of the following series:
S = a - (a/2!) + (a/3!) - (a/4!) + ……. to n
Write a program in Java to find the sum of the following series:
S = (2/a) + (3/a2) + (5/a3) + (7/a4) + ……. to n