level 4
#include"stdio.h"
double pow(double x,int n)
{
double s;
if(n==0)
s=1;
else if(n<0)
s=pow(x,n+1)*x;
else
s=pow(x,n-1)*x;
return s;
}
void main()
{
double x,s;
int n;
printf("请输入待求函数x^n");
scanf("%lf,%d",&x,&n);
s=pow(x,n);
printf("输出x^n的值%lf\n",s);
}
2013年12月17日 10点12分
1
level 13
double s;改成static double s;
楼主的代码真丑陋,学的谭浩强吧
2013年12月17日 10点12分
2
一语道破天机
2013年12月17日 13点12分
level 11
当n<0的时候,应该是不断除以x,其他就没问题了。
2013年12月17日 10点12分
3
谢谢,我去实践一下
2013年12月17日 12点12分
为什么还是不行,
2013年12月17日 12点12分