小编Adi*_* Om的帖子

递归阶乘函数程序为C中的大量输入返回0

我编写了程序,使用递归进行阶乘计算,如课堂上所教。我观察到:大于 65 的数的阶乘始终给出 0 的输出。

//program to recursively calculate the value of factorial for a given integer!

#include <stdio.h>
#include <stdint.h>

unsigned long rfacta(uint32_t n){
    if(n>0)
        return rfacta(n-1)*n;
    else
        return 1;
}

unsigned long rfactd(uint32_t n){
    if(n>0)
        return n*rfactd(n-1);
    else
        return 1;
}

int main(void){
    uint32_t number, methd;
    unsigned long fctorial;
    printf(" Enter 0 for call-time recursion\n Enter 1 for return-time recursion\n Enter 2 to print the table of passible factorials on this system\n\n");
    scanf("%d",&methd);
    switch(methd){
    case 0:
        printf("Compute factorial …
Run Code Online (Sandbox Code Playgroud)

c recursion

5
推荐指数
2
解决办法
595
查看次数

标签 统计

c ×1

recursion ×1