将一个数表示为两个素数之和

Representing a number as the sum of two prime numbers

我的代码有什么问题?为什么我没有得到任何输出? 我正在练习嵌入式系统。

running code screenshot

#include <stdio.h>

int checkP (int n)
{
    for (int i=2; i<n; i++)
        if(n%i==0)
            return (0);
    return (1);
}

int nextP (int n)
{
    do
     n++;
    while (!checkP(n));
    return n;
}

int main (void)
{
    int x = 34;  //user input
    for (int i = 2; i < x - 1; i = nextP(i))
    {
        if (checkP(x - 1)) {
            printf ("\n %d + %d", i, x-1);
        }
    }
}

x-1总是33,你要用x-i,这样ix-i的和就是x .

if 应该是这样的:

if (checkP(x - i)) {
     printf ("\n %d + %d", i, x-i);
}

https://ideone.com/jAIfa2

输出:

 3 + 31
 5 + 29
 11 + 23
 17 + 17
 23 + 11
 29 + 5
 31 + 3