在ISO C89中计算函数调用

时间:2015-10-25 11:20:49

标签: c function counting function-calls ansi-c

我必须在C中为我的作业写一个函数。 给定函数is_prime(n)和nth_prime(n),如果n是素数,则第一个返回1(如果不是,则返回0)和返回第n个素数的nth_prime,我必须写函数next_prime(count)它会计算它所调用的时间,然后返回" count-th"数字素数。 count必须是一个静态unsigned int变量。 如果n = 0(n用scanf给出),则必须将计数值复位为0,并且该函数返回第一个素数,2。
我不能使用结构,数组或递归。 我是编码的新手,我不知道该怎么做。 我使用Visual Studio 2010,我必须将其编译为ISO C89(ANSI C)。 这些函数必须写在库文件中,这是唯一要评估的函数,所以我不能在main()函数中使用count ++。 这是我到目前为止所做的事情。

unsigned int next_prime( unsigned int count ) {
    if( count == 0 ) {
        if ( n=!0 ) {                       
            return nth_prime( count );
            count++;
        } else {
            count = 0;
            return 2;
        }      
    } else {    
        if ( n=!0 ) {                       
            return nth_prime( count );
        } else {
            count = 0;
            return 2; 
        }       
    }
}   

1 个答案:

答案 0 :(得分:0)

这是一个符合您问题的功能:

{{1}}