import java.util.*;
public class Ch2Q39a
{public static void main(String[] args)
{int n;
double x, sum = 0;
Scanner kbd = new Scanner(System.in);
System.out.print("Enter x: ");
x = kbd.nextDouble();
System.out.print("Enter no of terms: ");
n = kbd.nextInt();
for(int i = 0; i <= n; i++)
sum += Math.pow(x, i)/fact(i);
System.out.println("Sum = "+ sum);
}
static long fact(int n)
{long f = 1;
for(int i = 1; i <= n; i++)
f *= i;
return f;
}
}
No comments:
Post a Comment