首页 > 其他分享 >歌德巴赫猜想

歌德巴赫猜想

时间:2023-06-04 15:46:40浏览次数:28  
标签:return int n% fun include 歌德巴赫猜想

一、问题描述:

 

二、设计思路:

 

 

三、程序流程图:

 

 

四、代码实现:

#include<stdio.h>
#include<math.h>
int fun(int n)
{
    int i;
    if(n==2)
        return 1;
    if(n%2==0)
        return 0;
    for(i=3;i<=sqrt(n);i+=2)
        if(n%i==0)
        return 0;
        return 1;
}

int main()
{
    int n,i,ok;
    while(scanf("%d",&n)!=EOF)
    {
        ok=0;//进入循环前先置标志位
    for(i=2;i<=n/2;i++)
    {
        if(fun(i)&&fun(n-i))
            {
                printf("%d %d\n",i,n-i);//i和n-i都是素数
                ok=1;
            }
        if(i!=2)
            i++;
        if(ok)
            break;//已经打印出所有结果  跳出循环
        }
    }

    return 0;
}

 

标签:return,int,n%,fun,include,歌德巴赫猜想
From: https://www.cnblogs.com/bzsc/p/17455768.html

相关文章