'commit'
This commit is contained in:
26
C++专题课程/基础知识/验证哥德巴赫猜想.cpp
Normal file
26
C++专题课程/基础知识/验证哥德巴赫猜想.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define MAX 1000
|
||||
int is_sushu(int n) {
|
||||
int i, mid;
|
||||
mid=(int)sqrt(n);
|
||||
for(i=2; i<=mid; i++)
|
||||
if(0 == n%i)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
int main() {
|
||||
int i, mid, n;
|
||||
|
||||
printf("Enter an even num: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
mid=n/2;
|
||||
for(i=2; i<=mid; i++) {
|
||||
if(is_sushu(i) && is_sushu(n-i))
|
||||
printf("%d = %d + %d\n", n, i, n-i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user