我的c程序永远在编译,永远不会停止。有什么问题吗?

问题描述 投票:0回答:1
#include <stdio.h>
#include <stdlib.h>

int factorial (int b);

int main (void) {

    int a;
    scanf("%d", &a);
    int fac = factorial(a);
    printf("Your final result is: %i", fac);

}

int factorial (int b) {
    if (b == 0) {
        return 0;
    }
    else if (b == 1) {
        return 1;
    }

    return b * factorial(b - 1);
}

在 cs50 的 Tideman 学习编程之后,我尝试学习递归,但事情甚至无法编译(更像是它不会停止),我非常悲伤和沮丧 rn :( 我正在使用 cs50 IDE 并不知何故从其库中获取 cs50 的函数,像 get_int() 一样,也不起作用?我很困惑。无论如何,如果你能看到代码中任何明显的错误,我可以修复 lmk!非常感谢

c compiler-construction cs50 break
1个回答
-1
投票

你的意思是?你的程序运行良好,不要忘记程序正在要求输入,也不要忘记你不应该给出很大的输入,因为你实现的解决方案不是最佳的(所以尝试输入小于10)

© www.soinside.com 2019 - 2024. All rights reserved.