C / C ++ program training 6 --- Goldbach conjecture

: Verify "each are an even number of not less than 6 and two Primes", enter an even number less than n-6, to find two prime numbers, and that their is n.

Language: C.

Entry: an even number of not less than the n 6.

Output: find the two prime numbers, and that their is n. Wherein the minimum output only the first set of data can be a prime number.

Example:

Enter 80

Output 80 = 73 + 7

#include <stdio.h>
int F (int m)
{
    int I;
    for (I = 2; I <m; I ++) // 2 from the start of the loop, to ensure that the first prime number is the smallest prime number qualified.
    {
        If (m == 0 I%)
            BREAK;
    }
    if (I == m) // When a prime number, there must be i = m, then use directly if the return value.
    {
        Return -1;
    }
    the else
    {
        return. 1;
    }
} // definition of a judgment "m" is not a function of the number of prime.
    int main ()
{
    int n-;
    int I =. 3;
    Scanf ( "% D", & n-);
    for (I =. 3; I <n-; I ++)
    {
        IF (F (I) == -. 1 && I% 2 == && F. 1 (Ni) == -. 1 && (Ni). 1% == 2)
        {
            printf("%d=%d+%d\n",n,i,n-i);
            break;
        }
    }
}

Guess you like

Origin www.cnblogs.com/ciarian/p/11930074.html