117. JAVA Program to Compute the 1!/1+2!/2+3!/3+ 4!/4+ …….+n!/n Series.
How does this program work?
- This program is used to find the Sum of the given series 1!/1+2!/2+3!/3+ 4!/4+ …….+n!/n using java.
- The integer entered by the user is stored in variable n i.e., last term for the given series.
- Declare variable sum and Initially initialize with 0, And also Declare another variable fact initialize with 1.
- First we need to calculate the factorial of number after that performed by sum for n terms.
Here is the code
//To Find the Sum of given series 1!/1+2!/2+3!/3+ 4!/4+ …….+n!/n
import java.util.Scanner;public class series
{
public static void main(String args[] )
{
int n,sum = 0,i,h=1;
System.out.println("Enter series of number:\n");
Scanner skill= new Scanner(System.in);
n=skill.nextInt();
for (i=1; i<= n; i++)
{
h=h*i;
sum=(sum+h)/i;
}
System.out.println("sum of series is="+sum);
}
}