From eefa5341eebe04ae5abf0751c737d2e6c3655058 Mon Sep 17 00:00:00 2001 From: windy Date: Sat, 12 Apr 2025 21:55:21 +0800 Subject: [PATCH 1/2] just test --- exercises/01_helloworld.c | 2 +- exercises/02_loop.c | 5 +++++ exercises/03_nested_loops.c | 7 +++++++ exercises/04_prime_number.c | 14 ++++++++++++++ exercises/05_josephus_ring.c | 22 +++++++++++++++++++++- 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/exercises/01_helloworld.c b/exercises/01_helloworld.c index e610016..140adb0 100644 --- a/exercises/01_helloworld.c +++ b/exercises/01_helloworld.c @@ -5,7 +5,7 @@ int main(){ // Print "Hello World!" to the console - + printf("Hello World!"); return 0; } \ No newline at end of file diff --git a/exercises/02_loop.c b/exercises/02_loop.c index 3e361e6..34b8bb7 100644 --- a/exercises/02_loop.c +++ b/exercises/02_loop.c @@ -8,6 +8,11 @@ int main(void) { //TODO + int i; + for (i= 1; i<=10;i++){ + printf("%d\n", i); + + } return 0; } \ No newline at end of file diff --git a/exercises/03_nested_loops.c b/exercises/03_nested_loops.c index d80c690..a819f4b 100644 --- a/exercises/03_nested_loops.c +++ b/exercises/03_nested_loops.c @@ -12,6 +12,13 @@ int main(void) { //TODO + int i, j; + for (i = 1; i <= 9; i++) { + for (j = 1; j <= i; j++) { + printf("%d*%d=%d\t", j, i, i * j); + } + printf("\n"); + } return 0; } \ No newline at end of file diff --git a/exercises/04_prime_number.c b/exercises/04_prime_number.c index 28e3f5f..83c078a 100644 --- a/exercises/04_prime_number.c +++ b/exercises/04_prime_number.c @@ -11,6 +11,20 @@ int main(void) for (i = 1; i <= 100; i++) { //TODO + int is_prime = 1; + if (i <= 1) { + is_prime = 0; + } else { + for (j = 2; j * j <= i; j++) { + if (i % j == 0) { + is_prime = 0; + break; + } + } + } + if (is_prime) { + max = i; + } } printf("max = %d\n", max); diff --git a/exercises/05_josephus_ring.c b/exercises/05_josephus_ring.c index 330f204..818e20a 100644 --- a/exercises/05_josephus_ring.c +++ b/exercises/05_josephus_ring.c @@ -22,7 +22,27 @@ int main(void) int step; /* 当前报数 */ //TODO - + // 初始化人员编号 + for (int i = 0; i < ALL_NUM; i++) { + people[i] = i + 1; + } + + left = ALL_NUM; + pos = 0; + step = 0; + + while (left > 0) { + if (people[pos] != 0) { + step++; + if (step == COUNT_NUM) { + printf("%d out \n", people[pos]); + people[pos] = 0; + step = 0; + left--; + } + } + pos = (pos + 1) % ALL_NUM; + } return 0; -- Gitee From eef4fd969b52facf302f50243de0d84d8394ce99 Mon Sep 17 00:00:00 2001 From: 13407115966 Date: Wed, 7 May 2025 14:08:41 +0800 Subject: [PATCH 2/2] stage-0 --- exercises/05_josephus_ring.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/exercises/05_josephus_ring.c b/exercises/05_josephus_ring.c index 818e20a..138a5e6 100644 --- a/exercises/05_josephus_ring.c +++ b/exercises/05_josephus_ring.c @@ -21,8 +21,6 @@ int main(void) int pos; /* 当前报数位置 */ int step; /* 当前报数 */ - //TODO - // 初始化人员编号 for (int i = 0; i < ALL_NUM; i++) { people[i] = i + 1; } -- Gitee