Question

Sum of Series 1!/1-2!/2+3!/3-4!/4+5!/5-….+n!/n

				
					ENTER THE Nth TERM
3
SUM OF SERIES=2
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class Series
{

    public static void main()
    {
        int n=0,i=0,j=0;
        long sum=0,fact=1;
        Scanner sc=new Scanner(System.in);
        System.out.println("ENTER THE Nth TERM");
        n=sc.nextInt();
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=i;j++)
            {
                fact=fact*j;
            }
            if(i%2==0)
            {
                sum=sum-(fact/i);
            }
            else
            {
                sum=sum+(fact/i);
            }
            fact=1;

        }
        System.out.println("SUM OF SERIES="+sum);
    }
}


				
			

Leave a Reply

Your email address will not be published. Required fields are marked *