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;

posted @ 2024-04-06 11:26  我要成为(c语言)高手  阅读(16)  评论(0)    收藏  举报