From 3cc35603fa993c4bf7be362b769826cb6a3c5d77 Mon Sep 17 00:00:00 2001 From: Hepper123 <1091720669@qq.com> Date: Tue, 9 Mar 2021 23:20:56 +0800 Subject: [PATCH] c --- level1/p03_Diophantus/README.md | 2 +- level1/p06_Goldbach/Goldbach.cpp | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 level1/p06_Goldbach/Goldbach.cpp diff --git a/level1/p03_Diophantus/README.md b/level1/p03_Diophantus/README.md index 021fd647..08c2f41f 100755 --- a/level1/p03_Diophantus/README.md +++ b/level1/p03_Diophantus/README.md @@ -12,6 +12,6 @@ 儿子比父亲先死四年, -年级是他的一半。 +年纪是他的一半。 问儿子死时丢番图多大? \ No newline at end of file diff --git a/level1/p06_Goldbach/Goldbach.cpp b/level1/p06_Goldbach/Goldbach.cpp new file mode 100644 index 00000000..2d8b982f --- /dev/null +++ b/level1/p06_Goldbach/Goldbach.cpp @@ -0,0 +1,59 @@ +#include + +int main() +{ + int i = 2; + int IsPrime = 1; + int a[50] = { 0 }; + int k = 0; + for (i = 2; i <= 100; i++) + { + IsPrime = 1; + for (int j = 2; j <= i / 2; j++) + { + if (i % j == 0) + { + IsPrime = 0; + break; + } + } + if (IsPrime == 1) + { + a[k] = i; + k++; + } + } + int sum = 0; + int h = 4; + for (h = 4; h <= 100; h = h + 2) + { + int s = 1; + for (int x = 0; x < k; x++) + { + for (int y = 0; y <= x; y++) + { + if (a[x] + a[y] == h) + { + s = 0; + break; + } + } + if (s == 0) + { + break; + } + } + if (s == 0) + { + sum++; + } + } + if (sum == 49) + { + printf("°ͺղ100Χȷ"); + } + else + { + printf("°ͺղ100Χڲȷ"); + } +} \ No newline at end of file