C语言for循环中嵌套递归函数,for只执行了最后一次

2025-02-23 22:27:08
推荐回答(2个)
回答1:

#include 

long fact(int n);

int main() {
int n;
long L;
for(n = 2;n < 10;n++) {
L = fact(n);
printf("%d! = %ld\n",n,L);
}
return 0;
}

long fact(int n) {
    if(n == 1 || n == 0) return 1;
return n*fact(n - 1);
}

回答2:

有printf输出的信息么、发上来看看、看代码没什么问题啊。