#include <stdio.h>
#include <stdlib.h>
int power(int x, int n) {
if (n == 0) {
return 1;
} else {
int temp = power(x,n/2);
temp = temp * temp;
if(n%2!=0)
temp = x * temp;
return temp;
}
}
int main() {
int a = 5, b = 3;
printf("%d = %d\n", a, power(a, b));
return 0;
}
整数幂(c语言)
于 2023-12-09 21:16:29 首次发布