diff --git a/【实践课外】5.循环结构2/7-1 求整数段和.c b/【实践课外】5.循环结构2/7-1 求整数段和.c new file mode 100644 index 0000000..222ab88 --- /dev/null +++ b/【实践课外】5.循环结构2/7-1 求整数段和.c @@ -0,0 +1,25 @@ +#include + +int main() { + int a, b, sum = 0; + + scanf("%d %d", &a, &b); + + for (int i = 0; i < (b - a + 1); i++) { + printf("%5d", a + i); + + sum += a + i; + + if (i % 5 == 4) { + printf("\n"); + } + } + + if ((b - a) % 5 != 4) { + printf("\n"); + } + + printf("Sum = %d\n", sum); + + return 0; +} diff --git a/【实践课外】5.循环结构2/7-1 求整数段和.jpg b/【实践课外】5.循环结构2/7-1 求整数段和.jpg new file mode 100644 index 0000000..eb46bba Binary files /dev/null and b/【实践课外】5.循环结构2/7-1 求整数段和.jpg differ diff --git a/【实践课外】5.循环结构2/7-2 循环-aaaa.c b/【实践课外】5.循环结构2/7-2 循环-aaaa.c new file mode 100644 index 0000000..c07de2a --- /dev/null +++ b/【实践课外】5.循环结构2/7-2 循环-aaaa.c @@ -0,0 +1,21 @@ +#include + +int main() { + int a, n, sum = 0; + + scanf("%d%d", &a, &n); + + for (int i = 1; i <= n; i++) { + int x = 0; + + for (int j = 0; j < i; j++) { + x = x * 10 + a; + } + + sum += x; + } + + printf("%d\n", sum); + + return 0; +} diff --git a/【实践课外】5.循环结构2/7-2 循环-aaaa.jpg b/【实践课外】5.循环结构2/7-2 循环-aaaa.jpg new file mode 100644 index 0000000..659a45a Binary files /dev/null and b/【实践课外】5.循环结构2/7-2 循环-aaaa.jpg differ diff --git a/【实践课外】5.循环结构2/7-3 循环-完数.c b/【实践课外】5.循环结构2/7-3 循环-完数.c new file mode 100644 index 0000000..a38c98b --- /dev/null +++ b/【实践课外】5.循环结构2/7-3 循环-完数.c @@ -0,0 +1,21 @@ +#include + +int main() { + int n, sum = 0; + + scanf("%d", &n); + + for (int i = 1; i < n; i++) { + if (n % i == 0) { + sum += i; + } + } + + if (sum == n) { + printf("YES\n"); + } else { + printf("NO\n"); + } + + return 0; +} diff --git a/【实践课外】5.循环结构2/7-3 循环-完数.jpg b/【实践课外】5.循环结构2/7-3 循环-完数.jpg new file mode 100644 index 0000000..b8afe19 Binary files /dev/null and b/【实践课外】5.循环结构2/7-3 循环-完数.jpg differ diff --git a/【实践课外】5.循环结构2/7-4 输出三角形字符阵列.c b/【实践课外】5.循环结构2/7-4 输出三角形字符阵列.c new file mode 100644 index 0000000..2cce9c1 --- /dev/null +++ b/【实践课外】5.循环结构2/7-4 输出三角形字符阵列.c @@ -0,0 +1,18 @@ +#include + +int main() { + int n; + char c = 'A'; + + scanf("%d", &n); + + for (int i = n; i >= 1; i--) { + for (int j = 1; j <= i; j++) { + printf("%c ", c++); + } + + printf("\n"); + } + + return 0; +} diff --git a/【实践课外】5.循环结构2/7-4 输出三角形字符阵列.jpg b/【实践课外】5.循环结构2/7-4 输出三角形字符阵列.jpg new file mode 100644 index 0000000..d630381 Binary files /dev/null and b/【实践课外】5.循环结构2/7-4 输出三角形字符阵列.jpg differ diff --git a/【实践课外】5.循环结构2/7-5 打印九九口诀表.c b/【实践课外】5.循环结构2/7-5 打印九九口诀表.c new file mode 100644 index 0000000..52e07df --- /dev/null +++ b/【实践课外】5.循环结构2/7-5 打印九九口诀表.c @@ -0,0 +1,17 @@ +#include + +int main() { + int n; + + scanf("%d", &n); + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= i; j++) { + printf("%d*%d=%-4d", j, i, i * j); + } + + printf("\n"); + } + + return 0; +} diff --git a/【实践课外】5.循环结构2/7-5 打印九九口诀表.jpg b/【实践课外】5.循环结构2/7-5 打印九九口诀表.jpg new file mode 100644 index 0000000..b873166 Binary files /dev/null and b/【实践课外】5.循环结构2/7-5 打印九九口诀表.jpg differ diff --git a/【实践课外】5.循环结构2/7-6 换硬币.c b/【实践课外】5.循环结构2/7-6 换硬币.c new file mode 100644 index 0000000..a2954ab --- /dev/null +++ b/【实践课外】5.循环结构2/7-6 换硬币.c @@ -0,0 +1,23 @@ +#include + +int main() { + int x, count = 0; + + scanf("%d", &x); + + for (int i = x / 5; i >= 1; i--) { + for (int j = x / 2; j >= 1; j--) { + for (int k = x; k >= 1; k--) { + if (i * 5 + j * 2 + k == x) { + printf("fen5:%d, fen2:%d, fen1:%d, total:%d\n", i, j, k, i + j + k); + + count++; + } + } + } + } + + printf("count = %d\n", count); + + return 0; +} diff --git a/【实践课外】5.循环结构2/7-6 换硬币.jpg b/【实践课外】5.循环结构2/7-6 换硬币.jpg new file mode 100644 index 0000000..66ce44a Binary files /dev/null and b/【实践课外】5.循环结构2/7-6 换硬币.jpg differ diff --git a/【实践课外】5.循环结构2/7-7 猜数字游戏.c b/【实践课外】5.循环结构2/7-7 猜数字游戏.c new file mode 100644 index 0000000..3b0f414 --- /dev/null +++ b/【实践课外】5.循环结构2/7-7 猜数字游戏.c @@ -0,0 +1,42 @@ +#include + +int main() { + int num, n, finished = 0; + + scanf("%d%d", &num, &n); + + for (int i = 1; i <= n; i++) { + int x; + + scanf("%d", &x); + + if (x < 0) { + printf("Game Over\n"); + + finished = 1; + break; + } else if (x == num) { + if (i == 1) { + printf("Bingo!\n"); + } else if (i <= 3) { + printf("Lucky You!\n"); + } else { + printf("Good Guess!\n"); + } + + finished = 1; + + break; + } else if (x < num) { + printf("Too small\n"); + } else { // x > num + printf("Too big\n"); + } + } + + if (finished == 0) { + printf("Game Over\n"); + } + + return 0; +} diff --git a/【实践课外】5.循环结构2/7-7 猜数字游戏.jpg b/【实践课外】5.循环结构2/7-7 猜数字游戏.jpg new file mode 100644 index 0000000..aa73772 Binary files /dev/null and b/【实践课外】5.循环结构2/7-7 猜数字游戏.jpg differ diff --git a/【实践课外】5.循环结构2/7-8 沙漏.c b/【实践课外】5.循环结构2/7-8 沙漏.c new file mode 100644 index 0000000..951230d --- /dev/null +++ b/【实践课外】5.循环结构2/7-8 沙漏.c @@ -0,0 +1,39 @@ +#include + +int main() { + int n; + + scanf("%d", &n); + + // 上半部分 + for (int i = n * 2 - 1; i >= 1; i -= 2) { + // 空格 + for (int j = 1; j <= (n * 2 - 1 - i) / 2; j++) { + printf(" "); + } + + // 沙漏主体 + for (int j = 1; j <= i; j++) { + printf("#"); + } + + printf("\n"); + } + + // 下半部分 + for (int i = 3; i <= n * 2 - 1; i+= 2) { + // 空格 + for (int j = 1; j <= (n * 2 - 1 - i) / 2; j++) { + printf(" "); + } + + // 沙漏主体 + for (int j = 1; j <= i; j++) { + printf("#"); + } + + printf("\n"); + } + + return 0; +} diff --git a/【实践课外】5.循环结构2/7-8 沙漏.jpg b/【实践课外】5.循环结构2/7-8 沙漏.jpg new file mode 100644 index 0000000..2ba77aa Binary files /dev/null and b/【实践课外】5.循环结构2/7-8 沙漏.jpg differ