这是我对递归的尝试。它编译并运行,但不显示我输入的数字的阶乘。我正在 Ubuntu 上使用 Geany 尝试此操作。
#include <stdio.h>
int fact(int n);
int main() {
int n;
printf("Give me a number");
scanf("%6d", &n);
fact(n);
}
int fact(int n) {
if (n <= 1)
return 1;
else
return n * fact(n - 1);
}
最佳答案
您缺少打印语句。 您可以将结果保存在变量中,然后打印它。
printf("%d",fact(n));
关于C递归练习不会显示输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55092291/