#include<stdio.h>
#include<math.h>
float main()
{
float fac(int n);
float Exp_Calculate(float x);
float x;
float y;
float E;
float EPS=0.00001;
char c1;
do
{
printf("input the value of x:\n");
scanf("%f",&x);
y=Exp_Calculate(x);
printf("the taile value is:\n");
printf("%f",y);
printf("\n");
E=abs(y-exp(x));
if(E<EPS)
printf("the value is:\n%.4f\n",y);
else
printf("the value is:-1\n");
printf("continue y/n\n");
scanf("%c",&c1);
}
while(c1=='y');
getch();
}
float fac(int n)
{
float f;
if(n<0)
{
printf("n<0,dataerror!");
}
else
if(n==0||n==1)
f=1;
else
f=fac(n-1)*n ;
return(f);
}
float Exp_Calculate(float x)
{
float sum=0;
int i;
for(i=0;i<20;i++)
sum+=pow(x,i)/(fac(i));
return(sum);
}
#include<math.h>
float main()
{
float fac(int n);
float Exp_Calculate(float x);
float x;
float y;
float E;
float EPS=0.00001;
char c1;
do
{
printf("input the value of x:\n");
scanf("%f",&x);
y=Exp_Calculate(x);
printf("the taile value is:\n");
printf("%f",y);
printf("\n");
E=abs(y-exp(x));
if(E<EPS)
printf("the value is:\n%.4f\n",y);
else
printf("the value is:-1\n");
printf("continue y/n\n");
scanf("%c",&c1);
}
while(c1=='y');
getch();
}
float fac(int n)
{
float f;
if(n<0)
{
printf("n<0,dataerror!");
}
else
if(n==0||n==1)
f=1;
else
f=fac(n-1)*n ;
return(f);
}
float Exp_Calculate(float x)
{
float sum=0;
int i;
for(i=0;i<20;i++)
sum+=pow(x,i)/(fac(i));
return(sum);
}