c语言 x的n次方 用函数


qq_我是超人_4
浏览 3139回答 1
1回答

天将明96

#include <stdio.h> //循环版 int myPow1(int x, int n) {     int result = 1;     if (n == 0) {         return result;     }     for (int i = 0; i < n; i++) {         result *= x;     }     return result; } //递归版 int myPow2(int x, int n) {     if (n == 0)         return 1;     if (n == 1)         return x;     if (n > 1)         return myPow2(x, n - 1) * x; } int main() {     printf("%d\n", myPow1(5, 4));     printf("%d\n", myPow2(5, 4)); }如果满足要求,望采纳!<(▰˘◡˘▰)>
打开App,查看更多内容
随时随地看视频慕课网APP