From c1c14e733fb3981180e1fb6f74ae4e320b9dabd8 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 31 Oct 2024 16:45:40 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E9=A2=9D=E5=A4=96=E7=BB=83=E4=B9=A0?= =?UTF-8?q?=E3=80=91=E9=80=89=E6=8B=A9=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 【额外练习】选择结构/7-33 选择-三数排序.c | 29 +++++++++++++++++++ 【额外练习】选择结构/7-34 选择-凯撒密码.c | 19 ++++++++++++ 【额外练习】选择结构/7-35 选择-简单的运算Ⅱ.c | 27 +++++++++++++++++ 【额外练习】选择结构/7-36 选择-三角形和圆.c | 26 +++++++++++++++++ .../7-38 选择-百分制转五分制.c | 23 +++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 【额外练习】选择结构/7-33 选择-三数排序.c create mode 100644 【额外练习】选择结构/7-34 选择-凯撒密码.c create mode 100644 【额外练习】选择结构/7-35 选择-简单的运算Ⅱ.c create mode 100644 【额外练习】选择结构/7-36 选择-三角形和圆.c create mode 100644 【额外练习】选择结构/7-38 选择-百分制转五分制.c diff --git a/【额外练习】选择结构/7-33 选择-三数排序.c b/【额外练习】选择结构/7-33 选择-三数排序.c new file mode 100644 index 0000000..f2069c5 --- /dev/null +++ b/【额外练习】选择结构/7-33 选择-三数排序.c @@ -0,0 +1,29 @@ +#include + +int main() { + int a, b, c; + + scanf("%d%d%d", &a, &b, &c); + + if (a > b) { + int temp = a; + a = b; + b = temp; + } + + if (a > c) { + int temp = a; + a = c; + c = temp; + } + + if (b > c) { + int temp = b; + b = c; + c = temp; + } + + printf("%d %d %d\n", a, b, c); + + return 0; +} diff --git a/【额外练习】选择结构/7-34 选择-凯撒密码.c b/【额外练习】选择结构/7-34 选择-凯撒密码.c new file mode 100644 index 0000000..c7d8487 --- /dev/null +++ b/【额外练习】选择结构/7-34 选择-凯撒密码.c @@ -0,0 +1,19 @@ +#include + +int main() { + char c; + + scanf("%c", &c); + + if (c >= 'a' && c <= 'z') { + c += 3; + if (c > 'z') c -= 26; + } else if (c >= 'A' && c <= 'Z') { + c += 3; + if (c > 'Z') c -= 26; + } + + printf("%c\n", c); + + return 0; +} diff --git a/【额外练习】选择结构/7-35 选择-简单的运算Ⅱ.c b/【额外练习】选择结构/7-35 选择-简单的运算Ⅱ.c new file mode 100644 index 0000000..b14b835 --- /dev/null +++ b/【额外练习】选择结构/7-35 选择-简单的运算Ⅱ.c @@ -0,0 +1,27 @@ +#include + +int main() { + double a, b, c; + + scanf("%lf%lf%lf", &a, &b, &c); + + if (a == 0) { + if (b == 0 && c != 0) { + printf("0\n"); + } else { + printf("1\n"); + } + } else { + double delta = b * b - 4 * a * c; + + if (delta > 0) { + printf("2\n"); + } else if (delta == 0) { + printf("1\n"); + } else { + printf("0\n"); + } + } + + return 0; +} diff --git a/【额外练习】选择结构/7-36 选择-三角形和圆.c b/【额外练习】选择结构/7-36 选择-三角形和圆.c new file mode 100644 index 0000000..2092398 --- /dev/null +++ b/【额外练习】选择结构/7-36 选择-三角形和圆.c @@ -0,0 +1,26 @@ +#include +#include + +int main() { + double a, b, c, r; + + scanf("%lf%lf%lf%lf", &a, &b, &c, &r); + + double s = (a + b + c) / 2.0; + + if (s <= a || s <= b || s <= c) { + printf("No\n"); + return 0; + } + + double area = sqrt(s * (s - a) * (s - b) * (s - c)); + double inRadius = area / s; + + if (r <= inRadius) { + printf("Yes\n"); + } else { + printf("No\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-38 选择-百分制转五分制.c b/【额外练习】选择结构/7-38 选择-百分制转五分制.c new file mode 100644 index 0000000..23ef499 --- /dev/null +++ b/【额外练习】选择结构/7-38 选择-百分制转五分制.c @@ -0,0 +1,23 @@ +#include + +int main() { + int t; + + scanf("%d", &t); + + if (t >= 90 && t <= 100) { + printf("A\n"); + } else if (t >= 80 && t <= 89) { + printf("B\n"); + } else if (t >= 70 && t <= 79) { + printf("C\n"); + } else if (t >= 60 && t <= 69) { + printf("D\n"); + } else if (t >= 0 && t <= 59) { + printf("E\n"); + } else { + printf("Score is error!\n"); + } + + return 0; +}