#include
#include
#define N 15
int fac(int x)
{
int s;
if(x==0||x==1)
{s=1;}
else
s=x*fac(x-1);
return(s);
}
float exp1(int i,float &x)
{
float result;
result=pow(x,i)/fac(i);
if(i==0)
{result=1;}
else
{
result=result+exp1(i-1,x);
}
return(result);
}
float sin1(int i,float x)
{
float sum=0;
float term;
int fac(int m);//函数声明
for(int n=0;n<=i ;n++)
{
int a = pow(-1,n);//-1的n次方
float b = pow(x,2*n+1);
int c = fac(2*n+1);//函数调用
term = a * b / c;
sum += term;
}
return sum;
}
float cos1(int i,float x)
{
float sum=0;
float term;
int fac(int m);//函数声明
for(int n=0;n<=i ;n++)
{
int a = pow(-1,n);//-1的n次方
float b = pow(x,2*n);
int c = fac(2*n);//函数调用
term = a * b / c;
sum += term;
}
return sum;
}
void main()
{
float z1,z2,z3,x;
printf("please input a number-1.57~1.57之间的数:");
scanf("%f",&x);
printf("the value of exp1 is:\n");
z1=exp1(N,x);
printf("%.8f\n",z1);
printf("the value of sin1 is:\n");
z2=sin1(N,x);
printf("%f\n",z2);
printf("the value of cos1 is:\n");
z3=cos1(N,x);
printf("%.8f\n",z3);
}
递归调用的次数太多了,堆栈满了。
scanf("%f",x);
改为scanf("%f",&x);
能不能把你的题目要求发过来????