Java Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
Answers
Answered by
0
Answer:
This is the required Java program for the question.
import java.util.*;
public class Sum {
public static void main(String args[]) {
double s=0.0,p=1.0,i;
int n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter limit - ");
n=sc.nextInt();
for(i=1;i<=n;i++) {
p*=i;
s+=i/p;
}
System.out.println("Sum of the series is: "+s);
sc.close();
}
}
Algorithm:
- START.
- Accept the limit, say n.
- Initialise s=0, p=1.0, i=1.
- Iterate loop in the range 1 to n.
- Multiply the value of p with loop variable.
- Add the value of i/p to s.
- Display the value of s.
- STOP.
Refer to the attachment.
Attachments:
Similar questions