#include
#include
int show(int number,int count);
int main()
{
int count;
int number;
while(scanf("%d%d",&number,&count)==2){
if(number==0){
printf("the answer is 0");
}
else{
if(count==0){
printf("the answer is 1");
}
if(count>0){
printf("the answer is %d\n",show(number,count));
}
}
printf("please try again:");
}
return 0;
}
int show(int number,int count){
if(count>0)
return show(number,(count-1))*number;
}
它的运行结果不对,查了好久看不出来为什么。
更奇怪的是把上述所有类型换成double以后,乱码了
#include
#include
double show(double number,double count);
int main()
{
double count;
double number;
while(scanf("%lf%lf",&number,&count)==2){
if(number==0){
printf("the answer is 0");
}
else{
if(count==0){
printf("the answer is 1");
}
if(count>0){
printf("the answer is %f\n",show(number,count));
}
}
printf("please try again:");
}
return 0;
}
double show(double number,double count){
if(count>0)
return show(number,(count-1))*number;
}
运行结果: