Welcome to ICSE Java Answers. Ask any questions you have related to Java and we will answer them.
Java is a registered trademark of Oracle. This site is in no way related to or endorsed by Oracle.

Program to print the sum of series 1-(1^0 !)/y+(2^2 !)/y^2 -(3^4 !)/y^3 +(4^6!)/y^4 ...

0 votes

1-(1^0 !)/y+(2^2 !)/y^2 -(3^4 !)/y^3 +(4^6!)/y^4          .... upto n terms

asked by YASH
edited by Ranjith

1 Answer

0 votes
import java.util.*;
class a
{
    public static void main()
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("enter the limit");
        int n=sc.nextInt();
        System.out.println("enter the no.");
        int y=sc.nextInt();
        int i,sign=1,m=0,fact=1,j,l=1;
        double sum=1.0;
        for(i=1;i<=n;i++,l++)
        {
            double k=Math.pow(i,m);
            m=m+2;
            for(j=1;j<=k;j++)
            {
                fact=fact*j;
            }
            sign=sign*(-1);
            sum=sum+(sign*(fact/(Math.pow(y,l))));
            fact=1;
        }
        System.out.println(sum);
    }
}
        
        
    
 
            
            
            
answered by Anshul kanaujia
...