Answers

2015-02-09T11:58:06+05:30
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);
    }   
}
0