I don't get why it works fine if you change all the double
into int
,
is there something wrong with my printf statements?
you use %f
or %lf
for double
, right?
/*
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();
}