Advertisements
Advertisements
प्रश्न
Write a program to find the sum of the following series:
S = 1 +
थोडक्यात उत्तर
उत्तर
import java.util.*;
public class Q1a
{ public static void main(String args[])
{int a = 1, n, fact = 1;
double term, sum = 0;
Scanner obj = new Scanner(System.in);
System.out.println("Enter the value of n");
n = obj.nextInt();
for (int i = 1; i <= n; i++)
{fact = 1;
for (int j = 1; j <= i; j++)
fact = fact * j;
term = (double) a / fact;
System.out.println(a + "/" + fact); // OPTIONAL PRINT
a = a + 2;
sum = sum + term;
}
System.out.printIn("Sum of the series = " + sum);
}}
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 1.1: Nested Loop - EXERCISES [पृष्ठ १४५]