相关疑难解决方法(0)

C中的递归因子程序在执行时挂起

我正在编写一个程序来显示计算给定数量200万次的阶乘所需的时间.我是在C/C++ Eclipse环境中使用Debian Linux编写的.当程序到达时int temp = n * rfact(n-1);,它会挂起并且不会执行任何其他操作.

这是我到目前为止所得到的:

#include <stdio.h>
#include <time.h>

//prototypes
int rfact(int n);

main()
{
    int n = 0;
    int i = 0;
    double result = 0.0;
    clock_t t;
    printf("Enter a value for n: ");
    scanf("%i", &n);

printf("n=%i\n", n);

    //get current time
    t = clock();

    //process factorial 2 million times
    for(i=0; i<2000000; i++)
    {
        rfact(n);
    }

    printf("n=%i\n", n);

    //get total time spent in the loop
    result = (clock() - t)/(double)CLOCKS_PER_SEC;

    //print result
    printf("runtime=%d\n", result); …
Run Code Online (Sandbox Code Playgroud)

c eclipse recursion factorial

1
推荐指数
1
解决办法
611
查看次数

标签 统计

c ×1

eclipse ×1

factorial ×1

recursion ×1