#include "stdio.h"
#include "math.h"
main()
{
int n,i,z,data=1;
double x,sum=1;
int e= /* 忘了e是多少了,自己填一下吧*/
printf("enter value of x:");
scanf("%d",x);
printf("enter number of terms(n):");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(z=1;z<=i;z++)
data=data*i;
sum=sum+x/z;
}
printf("\nthe approximated value of e^x:%f",sum);
printf("\nthe value of e^x using c library function:%f",exp(x));
printf("\nthe absolute difference between the two value: %f",abs(sum-exp(x)));
return 0;
}
应该可以,我这里没有编译器......
想学好编程还是要靠自己多编才行,作业抄抄能过,但知识还是自己的......
这回你看看对不对
#include "stdio.h"
#include
#include "math.h"
void main(){
int n;
float x,t=1,sum=1;
printf("enter value of x:");
scanf("%f",&x);
printf("enter number of terms(n):");
scanf("%d",&n);
for (int i=1;i<=n;i++){
t/=i;
t*=x;
sum+=t;
}
printf("the approximated value of e^x:%16.12f\n",sum);
printf("the value of e^x using c library function:%16.12f\n",exp(x));
printf("the absolute difference between the two value: %16.16f\n",abs(sum-exp(x)));
}