Computer Science, asked by parikshith, 1 year ago

Solve the series and print the sum
1-x^2/2!+x^3/3!-x^4/4!.........x^n/n!
in blueJ

Answers

Answered by reshsekar
2
public class loop
{
   public void main( int x,int n)
   {
       int sum = 1;
       int sign = -1;
       for(int i = 2 ; i <= n ; i++)
       {
           int num = (int)Math.pow(x,i);
           int fact = 1;
           for(int j = 1; j<=i ; j++)
           {
             fact = fact * j;
            }
           
           int term = num/fact;
           sum = sum + (term * sign);
           sign = sign * -1;
        }
        
        System.out.println( " the sum is  :" + sum);
    }   
}
Similar questions