#include <stdio.h>
int num(int n,int k)
{
static int count = 0; //必须用静态变量来定义count,count每次调用不会被释放
int sum = 1;
if(k == 0)
return 1;
if(count == k)
return 1;
count++;
sum = n*num(n,k);
return sum;
}
int main()
{
int i;
i = num(3,2);
printf("%d\n",i);
return 0;
}
用递归实现n的k次方
最新推荐文章于 2024-07-11 20:41:32 发布