用函数喽
#include <stdio.h> int n_pow(int x, int n) { int i, t = 1; for(i = 0; i < n; i++) { t = t * x; } return t; } int main() { int a = n_pow(2, 3); printf("2 ^ 3 is %d\n", a); a = n_pow(5, 2); printf("5 ^ 2 is %d\n", a); }
2023-10-18 12:11:10
用函数喽
#include <stdio.h> int n_pow(int x, int n) { int i, t = 1; for(i = 0; i < n; i++) { t = t * x; } return t; } int main() { int a = n_pow(2, 3); printf("2 ^ 3 is %d\n", a); a = n_pow(5, 2); printf("5 ^ 2 is %d\n", a); }