我不明白为什么如果你把所有的都double
改成,它工作得很好int
,
我的 printf 语句有问题吗?
您使用%f
or%lf
对double
吗?
/*
double power(double a, int b) that calculates the power ab. You are allowed to use the
multiplication operator *.
*/
#include <stdio.h>
#include <conio.h>
double power(double a,int b)
{
double buffer;
if(b > 1)
{
buffer = a * power(a,b-1);
return buffer;
}
else
return a;
}
int main(void)
{
double a;
int b;
int buffer;
scanf("%f",&a);
scanf("%d",&b);
buffer = power(a,b);
printf("%f",buffer);
getch();
}