#include <math.h>
int i,k,m,t;
int xm=(int)x;
double sum;
double e ;
double ef;
double z ;
double sub=x-xm;
m=1; //阶乘算法分母
e=1.0; //e的xm
ef=1.0;
t=10; //算法精度
z=1; //分子初始化
sum=1;
// printf("x=%f\n",x);
// printf("sub=%f\n",sub);
if (xm<0) { //判断xm是否大于0?
xm=(-xm);
for(k=0;k<xm;k++){ef*=2.718281;}
e/=ef;
}
else { for(k=0;k<xm;k++){e*=2.718281;} }
// printf("e=%f\n",e);
// printf("xm=%d\n",xm);
for(i=1;i<t;i++){
m*=i;
z*=sub;
sum+=z/m;
}
return sum*e;
}
int main(viod)
{
double a;
double b;
double c;
do
{
printf("Input a double data:\n");
scanf("%lf",&a);
printf("Just input a data:%f\n",a);
b=exp(a);
c=myexp(a);
printf("The result of exp() funtion is: %f\n",b);
printf("The result of myexp() funtion is: %f\n\n",c);
}
while(1);
return (0);
}