Homework record-Power function calculation
include <stdio.h>
double f(double n,double m){
if (m==0) {
return 1;
}
else{
return f(n,m-1)*n;
}
}
int main(int argc, const char * argv[]){
double a,b=0,c;
printf("Please enter the base:");
scanf("%lf",&a);
printf("Please enter the exponent:");
scanf("%lf",&c);
if (c>=0) {
b=f(a,c);
}
if (c<0) {
c=-c;
b=1/f(a,c);
}
printf("\nOutput: %lf raised to the power of %lf is: %lf",a,c,b);
return 0;
浙公网安备 33010602011771号