当前位置:网站首页>Goldbach conjecture C language

Goldbach conjecture C language

2022-07-07 08:52:00 Please Sit Down

Goldbach conjecture : Enter a value greater than 6 An even number of , You can always find two primes , Make the sum of these two primes exactly equal to the even number .
#include <stdio.h>
#include <conio.h>
int prime(int n){
    int k, flag = 1;
    for (k = 2; k <= n/2 + 1; k++)
        if (n % k == 0){
            flag = 0 ;
            break;
        }
    return flag;
}
void main(){
    int num, a;
    // clrscr();
    do{
        printf("Please input an even number:");
        scanf("%d", &num);
    } while (num <= 6 || num % 2 == 1);
    for (a = 2; a <= num / 2 + 1; a++)
        if (prime(a) && prime(num - a))
            printf("\n %d = %d + %d ", num, a, num - a);
}

 

原网站

版权声明
本文为[Please Sit Down]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130629582188.html