
Program to sum the series 1+1/1!+1/2!+1/3!+....n

import java.util.*;
class Series
{
public static void main(String[]args)
{
System.out.print("Enter the value of n : ");
Scanner sc=new Scanner(System.in);
int n,i;
n=sc.nextInt();
double S=0,f=0;
for(i=1;i<n;i++)
{
f=fact(i);
S=S+(1/f);
}
System.out.println("The sum ="+(1+S));
}
public static double fact(int num)
{
int f=1,j;
for(j=1;j<=num;j++)
{
f=f*j;
}
return(f);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.