From c6fded82f93f233996840e58dfd8c5c9c2cd2a48 Mon Sep 17 00:00:00 2001 From: Powfu <1875065753@qq.com> Date: Thu, 14 Dec 2023 13:15:58 +0000 Subject: [PATCH] =?UTF-8?q?add=202101040022/chapter=5F1/=E6=B1=82=E7=B4=A0?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E4=B8=AA=E6=95=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Powfu <1875065753@qq.com> --- ...5\260\347\232\204\344\270\252\346\225\260" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "2101040022/chapter_1/\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260" diff --git "a/2101040022/chapter_1/\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260" "b/2101040022/chapter_1/\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260" new file mode 100644 index 00000000..ce154c80 --- /dev/null +++ "b/2101040022/chapter_1/\346\261\202\347\264\240\346\225\260\347\232\204\344\270\252\346\225\260" @@ -0,0 +1,35 @@ +#include +#include + +int num(int n) +{ + for(int i = 2; i <= sqrt(n); i++) + { + if(n % i == 0) + { + return 0; + } + } + return 1; +} + +int main() +{ + int n = 0; + int count = 0; + scanf("%d", &n); + if(n == 0 || n == 1) + { + printf("素数的个数是%d", count); + return 0; + } + for(int i = 2; i <= n; i++) + { + if(num(i) == 1) + { + count++; + } + } + printf("素数的个数是%d", count); + return 0; +} \ No newline at end of file -- Gitee