C 输出双素数的程序

C 输出双素数的程序,c,C,我需要写一个代码,让你输入一个数字,它检查给定的数字是否是一个双素数,后面是素数。以下是我到目前为止的情况: int isPrime (int Value){ int Number; for (Number=2; Number <= Value-1; Number++){ if (Value % Number ==0) return 0; else return 1; } } int n

我需要写一个代码,让你输入一个数字,它检查给定的数字是否是一个双素数,后面是素数。以下是我到目前为止的情况:

int isPrime (int Value){
    int Number;
        for (Number=2; Number <= Value-1; Number++){
        if (Value % Number ==0)
            return 0;
        else
            return 1;
}
}
int nextPrime(int current){
    while (1){
    if (isPrime(current))
        return current;
        current++;
    }
}
int main(){
    int a;
    int First = nextPrime (a);
    int Second = nextPrime(First + 1);
    scanf("%d", &a);
    if (Second - First == 2) {
        printf("%d and %d are twin primes.", First, Second);
    } else {
        printf("%d and %d are not twin primes.", First, Second);
    }
    return 0;
}
目前,a在第一次调用NextTime时未初始化。要获取除未定义行为以外的任何内容,您需要在调用scanf之前读取输入值,以便其值已初始化为用户的输入:

int a;
int First;
int Second;

scanf("%d", &a); /* move this line before the nextPrime calls */
First = nextPrime (a);
Second = nextPrime(First + 1);

非常感谢你!成功了!它现在工作得很好。总是一些小事。我是C语言编程新手,似乎在任何地方都找不到任何帮助,我也不太理解它,所以我不知道我必须转换代码的这一部分。但再次非常感谢你!:@提米很高兴这有帮助。为了让未来的读者更容易知道他们是否有类似的问题,并让本问答帮助他们,我建议您编辑您的问题,包括您遇到的问题的描述,例如代码编译,但程序似乎卡住了,从不打印任何内容,或者当我输入X时,我希望。。。但是我得到。。。相反,您可以发布您得到的错误或预期的输出吗?