diff --git a/【实践课外】4.循环结构1/7-1 最大公约数和最小公倍数.c b/【实践课外】4.循环结构1/7-1 最大公约数和最小公倍数.c new file mode 100644 index 0000000..d53067a --- /dev/null +++ b/【实践课外】4.循环结构1/7-1 最大公约数和最小公倍数.c @@ -0,0 +1,20 @@ +#include + +int gcd(int x, int y) { + if (x == 0) return y; + return gcd(y % x, x); +} + +int lcm(int x, int y) { + return x / gcd(x, y) * y; +} + +int main() { + int m, n; + + scanf("%d%d", &m, &n); + + printf("%d %d\n", gcd(m, n), lcm(m, n)); + + return 0; +} diff --git a/【实践课外】4.循环结构1/7-1 最大公约数和最小公倍数.jpg b/【实践课外】4.循环结构1/7-1 最大公约数和最小公倍数.jpg new file mode 100644 index 0000000..79b5bd2 Binary files /dev/null and b/【实践课外】4.循环结构1/7-1 最大公约数和最小公倍数.jpg differ diff --git a/【实践课外】4.循环结构1/7-2 判断一个整数是否为素数.c b/【实践课外】4.循环结构1/7-2 判断一个整数是否为素数.c new file mode 100644 index 0000000..249c367 --- /dev/null +++ b/【实践课外】4.循环结构1/7-2 判断一个整数是否为素数.c @@ -0,0 +1,28 @@ +#include + +int main() { + int x; + + scanf("%d", &x); + + if (x <= 1) { + printf("No\n"); + } else { + int is_prime = 1; + + for (int i = 2; i <= x / i; i++) { + if (x % i == 0) { + is_prime = 0; + break; + } + } + + if (is_prime == 1) { + printf("Yes\n"); + } else { + printf("No\n"); + } + } + + return 0; +} diff --git a/【实践课外】4.循环结构1/7-2 判断一个整数是否为素数.jpg b/【实践课外】4.循环结构1/7-2 判断一个整数是否为素数.jpg new file mode 100644 index 0000000..001a7f3 Binary files /dev/null and b/【实践课外】4.循环结构1/7-2 判断一个整数是否为素数.jpg differ diff --git a/【实践课外】4.循环结构1/7-3 循环-最小值.c b/【实践课外】4.循环结构1/7-3 循环-最小值.c new file mode 100644 index 0000000..fd73acb --- /dev/null +++ b/【实践课外】4.循环结构1/7-3 循环-最小值.c @@ -0,0 +1,21 @@ +#include + +int main() { + int n, min = 2147483647; + + scanf("%d", &n); + + for (int i = 0; i < n; i++) { + int x; + + scanf("%d", &x); + + if (x < min) { + min = x; + } + } + + printf("%d\n", min); + + return 0; +} diff --git a/【实践课外】4.循环结构1/7-3 循环-最小值.jpg b/【实践课外】4.循环结构1/7-3 循环-最小值.jpg new file mode 100644 index 0000000..c666919 Binary files /dev/null and b/【实践课外】4.循环结构1/7-3 循环-最小值.jpg differ diff --git a/【实践课外】4.循环结构1/7-4 最佳情侣身高差.c b/【实践课外】4.循环结构1/7-4 最佳情侣身高差.c new file mode 100644 index 0000000..7702863 --- /dev/null +++ b/【实践课外】4.循环结构1/7-4 最佳情侣身高差.c @@ -0,0 +1,22 @@ +#include + +int main() { + int n; + + scanf("%d\n", &n); + + for (int i = 1; i <= n; i++) { + char c; + double h; + + scanf("%c %lf\n", &c, &h); + + if (c == 'M') { + printf("%.2lf\n", h / 1.09); + } else { // c == 'F' + printf("%.2lf\n", h * 1.09); + } + } + + return 0; +} diff --git a/【实践课外】4.循环结构1/7-4 最佳情侣身高差.jpg b/【实践课外】4.循环结构1/7-4 最佳情侣身高差.jpg new file mode 100644 index 0000000..632a55a Binary files /dev/null and b/【实践课外】4.循环结构1/7-4 最佳情侣身高差.jpg differ diff --git a/【实践课外】4.循环结构1/7-5 循环-求和.c b/【实践课外】4.循环结构1/7-5 循环-求和.c new file mode 100644 index 0000000..39fe503 --- /dev/null +++ b/【实践课外】4.循环结构1/7-5 循环-求和.c @@ -0,0 +1,19 @@ +#include + +int main() { + int m, n, s1 = 0, s2 = 0; + + scanf("%d%d", &m, &n); + + for (int i = m; i <= n; i++) { + if (i % 2 == 1) { + s1 += i * i; + } else { // i % 2 == 0 + s2 += i * i * i; + } + } + + printf("%d %d\n", s1, s2); + + return 0; +} diff --git a/【实践课外】4.循环结构1/7-5 循环-求和.jpg b/【实践课外】4.循环结构1/7-5 循环-求和.jpg new file mode 100644 index 0000000..0d0a925 Binary files /dev/null and b/【实践课外】4.循环结构1/7-5 循环-求和.jpg differ diff --git a/【实践课外】4.循环结构1/7-6 循环-各位之和.c b/【实践课外】4.循环结构1/7-6 循环-各位之和.c new file mode 100644 index 0000000..a3d2403 --- /dev/null +++ b/【实践课外】4.循环结构1/7-6 循环-各位之和.c @@ -0,0 +1,17 @@ +#include + +int main() { + long long n; + int ans = 0; + + scanf("%lld", &n); + + while (n != 0) { + ans += n % 10; + n /= 10; + } + + printf("%d\n", ans); + + return 0; +} diff --git a/【实践课外】4.循环结构1/7-6 循环-各位之和.jpg b/【实践课外】4.循环结构1/7-6 循环-各位之和.jpg new file mode 100644 index 0000000..ee14b0d Binary files /dev/null and b/【实践课外】4.循环结构1/7-6 循环-各位之和.jpg differ diff --git a/【实践课外】4.循环结构1/7-7 输出闰年.c b/【实践课外】4.循环结构1/7-7 输出闰年.c new file mode 100644 index 0000000..5d90c04 --- /dev/null +++ b/【实践课外】4.循环结构1/7-7 输出闰年.c @@ -0,0 +1,27 @@ +#include + +int main() { + int year; + + scanf("%d", &year); + + if (2000 < year && year <= 2100) { + int count = 0; + + for (int i = 2001; i <= year; i++) { + if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) { + printf("%d\n", i); + + count++; + } + } + + if (count == 0) { + printf("None\n"); + } + } else { + printf("Invalid year!\n"); + } + + return 0; +} diff --git a/【实践课外】4.循环结构1/7-7 输出闰年.jpg b/【实践课外】4.循环结构1/7-7 输出闰年.jpg new file mode 100644 index 0000000..655c4fe Binary files /dev/null and b/【实践课外】4.循环结构1/7-7 输出闰年.jpg differ diff --git a/【实践课外】4.循环结构1/7-8 循环-奇数分之一序列前N项和.c b/【实践课外】4.循环结构1/7-8 循环-奇数分之一序列前N项和.c new file mode 100644 index 0000000..54acf9c --- /dev/null +++ b/【实践课外】4.循环结构1/7-8 循环-奇数分之一序列前N项和.c @@ -0,0 +1,16 @@ +#include + +int main() { + int n; + double ans = 0; + + scanf("%d", &n); + + for (int i = 0; i < n; i++) { + ans += 1.0 / (i * 2 + 1); + } + + printf("%.2lf\n", ans); + + return 0; +} diff --git a/【实践课外】4.循环结构1/7-8 循环-奇数分之一序列前N项和.jpg b/【实践课外】4.循环结构1/7-8 循环-奇数分之一序列前N项和.jpg new file mode 100644 index 0000000..494185c Binary files /dev/null and b/【实践课外】4.循环结构1/7-8 循环-奇数分之一序列前N项和.jpg differ