C语言实现浮点数的整数次幂函数 my_power - 循环方法
#include <stdio.h>
float my_power(float x, int n) { float result = 1.0; int i;
if (n >= 0) {
for (i = 0; i < n; i++) {
result *= x;
}
} else {
for (i = 0; i > n; i--) {
result /= x;
}
}
return result;
}
int main() { float x = 3.14; int n = -2; float result = my_power(x, n);
printf("%.6f\n", result);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/pLnw 著作权归作者所有。请勿转载和采集!