解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
public static double fact(int n){
if(n==1)
return 1;
else
return n*fact(n-1);
}
public static double mypow(double x,int n){
return Math.pow(x,n);
}
public static void main(String []args){
Scanner sc=new Scanner(System.in);
double x=sc.nextDouble();
int n=sc.nextInt();
double s=0.0,sum=0.0;
for(int i=1;i<=n;i++){
s=mypow(-1,i+1)*mypow(x,i)/fact(i);
sum=sum+s;
}
System.out.printf("%.4f",sum);
}
}