结果如图:
代码如下:
int pow(int x, int y) { int i, t; if (y == 0) t = 1; else { if (y < 0) y = -y; else y = y; t = 1; for (i = 0; i < y; i++) t = t * x; } return t; } #include<stdio.h> int main() { int x, y, t; printf("输入底数和指数:"); scanf("%d %d", &x, &y); if (y < 0) printf("1/%d\n", t = pow(x, y)); else printf("%d\n", t = pow(x, y)); return 0; }