[求助]怎么用递归调用编x的n次方
请教大家:怎么用递归调用来编写x的n次方?谢谢!
#include <stdlib.h>
#include <stdio.h>
void square(int x, int n, int *result);
int main(void)
{
int x, n, result = 1;
printf("Enter x and n: \n");
scanf("%d %d", &x, &n);
square(x, n, &result);
printf("result = %d\n", result);
exit(0);
}
void square(int x, int n, int *result)
{
if (n > 0) {
(*result) *= x;
square(x, --n, &(*result));
}
}