*循环-04. 验证“哥德巴赫猜想”

 1 /*
 2  * Main.c
 3  * C4-循环-04. 验证“哥德巴赫猜想”
 4  *  Created on: 2014年7月23日
 5  *      Author: Boomkeeper
 6  *****部分通过*****
 7  */
 8 
 9 #include <stdio.h>
10 
11 /*判断n是否为素数的函数*/
12 int isPrime(int n) {
13     int j, x;
14     for (j = 2; j < n; j++)
15         if (n % j == 0) {
16             x = 0;
17             break;
18         } else
19             x = 1;
20     return x;
21 }
22 
23 int main() {
24 
25     long n, i;
26 
27 //    printf("请输入一个不小于6的偶数:
");
28     scanf("%ld", &n);
29 
30     for (i = 3; i < (n / 2); i++) {
31         if (isPrime(i) != 0)
32             if (isPrime(n - i) != 0){
33                 //只要将第一个最小的输出就停止循环
34                 printf("%ld = %ld + %ld", n, i, n - i);
35                 i = n;
36             }
37     }
38 
39     return 0;
40 }

题目链接:

http://pat.zju.edu.cn/contests/basic-programming/%E5%BE%AA%E7%8E%AF-04

原文地址:https://www.cnblogs.com/boomkeeper/p/C4.html