project3_7
import java.io.*;
public class p3_7
{
public static void main(String[] args) throws IOException
{
BufferedReader keyin= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the number x of e^x");
int x = Integer.parseInt(keyin.readLine());
System.out.println("Please enter the number n ");
int n = Integer.parseInt(keyin.readLine());
double i,j,k=1,s,m=1,sum=0;
for(i=0;i<=n;i++) { for(j=i;j>0;j--)
k=k*j;
for(s=i;s>0;s--)
m=m*x;
sum=sum+(m/k);
}
System.out.println("e^x = "+sum);
}
}
0 Comments:
張貼留言
<< Home