083.验证歌德巴赫猜想
        【摘要】 
                    #include<stdio.h>#include<math.h>int fflag(int n);void main(){    int i,j,n;    long max;    clrscr();    puts("=============================================...
    
    
    
    
  
   - 
    
     
    
    
     
      #include<stdio.h>
     
    
 
   - 
    
     
    
    
     
      #include<math.h>
     
    
 
   - 
    
     
    
    
     
      int fflag(int n);
     
    
 
   - 
    
     
    
    
     
      void main()
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         int i,j,n;
     
    
 
   - 
    
     
    
    
         long max;
     
    
 
   - 
    
     
    
    
         clrscr();
     
    
 
   - 
    
     
    
    
         puts("============================================================");
     
    
 
   - 
    
     
    
    
         puts("|| This program will verify the Goldbach Guess. ||");
     
    
 
   - 
    
     
    
    
         puts("|| That is any positive even number can be broken up into ||");
     
    
 
   - 
    
     
    
    
         puts("|| the sum of two prime numbers. ||");
     
    
 
   - 
    
     
    
    
         puts("|| e.g., 4=2+2, 6=3+3, 8=3+5, 10=3+7, 12=5+7,... ||");
     
    
 
   - 
    
     
    
    
         puts("============================================================");
     
    
 
   - 
    
     
    
    
         printf("\n >> Please input the scale n you want to verify : ");
     
    
 
   - 
    
     
    
    
         scanf("%ld",&max);
     
    
 
   - 
    
     
    
    
         printf("\n >> Now the program starts to verify the even number\n");
     
    
 
   - 
    
     
    
    
         printf(" >> less than %ld equals to sum of two prime numbers.\n\n",max);
     
    
 
   - 
    
     
    
    
         for(i=4,j=0;i<=max;i+=2)
     
    
 
   - 
    
     
    
    
     
          {
     
    
 
   - 
    
     
    
    
             for(n=2;n<i;n++)         /*将偶数i分解为两个整数*/
     
    
 
   - 
    
     
    
    
                 if(fflag(n))         /*分别判断两个整数是否均为素数*/
     
    
 
   - 
    
     
    
    
                     if(fflag(i-n))
     
    
 
   - 
    
     
    
    
     
                      {
     
    
 
   - 
    
     
    
    
     		    printf("%4d=%2d+%2d ",i,n,i-n);        /*若均是素数则输出*/
     
    
 
   - 
    
     
    
    
     
      		    j++;
     
    
 
   - 
    
     
    
    
     		    if(j==5)
     
    
 
   - 
    
     
    
    
     
      		    {
     
    
 
   - 
    
     
    
    
     			printf("\n");
     
    
 
   - 
    
     
    
    
     
      			j=0;
     
    
 
   - 
    
     
    
    
     
      		    }
     
    
 
   - 
    
     
    
    
                         break;
     
    
 
   - 
    
     
    
    
     
                      }
     
    
 
   - 
    
     
    
    
                 if(n==i)  printf("error %d\n",i);
     
    
 
   - 
    
     
    
    
     
          }
     
    
 
   - 
    
     
    
    
         puts("\n >> Press any key to quit...");
     
    
 
   - 
    
     
    
    
         getch();
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
   - 
    
     
    
    
      
     
    
 
   - 
    
     
    
    
     
      int fflag(int i) /*判断是否为素数*/
     
    
 
   - 
    
     
    
    
     
      {
     
    
 
   - 
    
     
    
    
         int j;
     
    
 
   - 
    
     
    
    
         if(i<=1)return 0;
     
    
 
   - 
    
     
    
    
         if(i==2)return 1;
     
    
 
   - 
    
     
    
    
         if(!(i%2))return 0;     /*if no,return 0*/
     
    
 
   - 
    
     
    
    
         for(j=3;j<=(int)(sqrt((double)i)+1);j+=2)
     
    
 
   - 
    
     
    
    
             if(!(i%j))return 0;
     
    
 
   - 
    
     
    
    
         return 1;              /*if yes,return 1*/
     
    
 
   - 
    
     
    
    
     
      }
     
    
 
  
 
文章来源: blog.csdn.net,作者:程序员编程指南,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/weixin_41055260/article/details/124518658
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        - 点赞
 - 收藏
 - 关注作者
 
            
           
评论(0)