diff --git a/【实践课内】2.选择结构1/7-1 整数绝对值.c b/【实践课内】2.选择结构1/7-1 整数绝对值.c new file mode 100644 index 0000000..668380d --- /dev/null +++ b/【实践课内】2.选择结构1/7-1 整数绝对值.c @@ -0,0 +1,15 @@ +#include + +int main() { + int x; + + scanf("%d", &x); + + if (x < 0) { + printf("%d\n", -x); + } else { + printf("%d\n", x); + } + + return 0; +} diff --git a/【实践课内】2.选择结构1/7-1 整数绝对值.jpg b/【实践课内】2.选择结构1/7-1 整数绝对值.jpg new file mode 100644 index 0000000..e96d7ad Binary files /dev/null and b/【实践课内】2.选择结构1/7-1 整数绝对值.jpg differ diff --git a/【实践课内】2.选择结构1/7-2 偶数乘2奇数乘3.c b/【实践课内】2.选择结构1/7-2 偶数乘2奇数乘3.c new file mode 100644 index 0000000..21e2068 --- /dev/null +++ b/【实践课内】2.选择结构1/7-2 偶数乘2奇数乘3.c @@ -0,0 +1,17 @@ +#include + +int main() { + int x; + + scanf("%d", &x); + + if (x % 2 == 0) { + x *= 2; + } else { + x *= 3; + } + + printf("y=%d\n", x); + + return 0; +} diff --git a/【实践课内】2.选择结构1/7-2 偶数乘2奇数乘3.jpg b/【实践课内】2.选择结构1/7-2 偶数乘2奇数乘3.jpg new file mode 100644 index 0000000..789e6c8 Binary files /dev/null and b/【实践课内】2.选择结构1/7-2 偶数乘2奇数乘3.jpg differ diff --git a/【实践课内】2.选择结构1/7-3 成绩判定.c b/【实践课内】2.选择结构1/7-3 成绩判定.c new file mode 100644 index 0000000..b88d6db --- /dev/null +++ b/【实践课内】2.选择结构1/7-3 成绩判定.c @@ -0,0 +1,17 @@ +#include + +int main() { + int x; + + scanf("%d", &x); + + if (60 <= x && x <= 100) { + printf("Pass\n"); + } else if (0 <= x && x < 60) { + printf("No Pass\n"); + } else { // x < 0 || x > 100 + printf("Data Error\n"); + } + + return 0; +} diff --git a/【实践课内】2.选择结构1/7-3 成绩判定.jpg b/【实践课内】2.选择结构1/7-3 成绩判定.jpg new file mode 100644 index 0000000..7756cd2 Binary files /dev/null and b/【实践课内】2.选择结构1/7-3 成绩判定.jpg differ diff --git a/【实践课内】2.选择结构1/7-4 选择-计算器2.c b/【实践课内】2.选择结构1/7-4 选择-计算器2.c new file mode 100644 index 0000000..5d4b243 --- /dev/null +++ b/【实践课内】2.选择结构1/7-4 选择-计算器2.c @@ -0,0 +1,24 @@ +#include + +int main() { + int a, b; + char op; + + scanf("%d %c %d", &a, &op, &b); + + if (op == '+') { + printf("%d\n", a + b); + } else if (op == '-') { + printf("%d\n", a - b); + } else if (op == '*') { + printf("%d\n", a * b); + } else if (op == '/' && b != 0) { + printf("%.2lf\n", (double)a / b); + } else if (op == '%' && b != 0) { + printf("%d\n", a % b); + } else { + printf("Error\n"); + } + + return 0; +} diff --git a/【实践课内】2.选择结构1/7-4 选择-计算器2.jpg b/【实践课内】2.选择结构1/7-4 选择-计算器2.jpg new file mode 100644 index 0000000..1c7aa88 Binary files /dev/null and b/【实践课内】2.选择结构1/7-4 选择-计算器2.jpg differ diff --git a/【实践课内】2.选择结构1/7-5 计算油费.c b/【实践课内】2.选择结构1/7-5 计算油费.c new file mode 100644 index 0000000..bb6754e --- /dev/null +++ b/【实践课内】2.选择结构1/7-5 计算油费.c @@ -0,0 +1,32 @@ +#include + +const double P90 = 6.95; +const double P93 = 7.44; +const double P97 = 7.93; + +int main() { + int a, b; + char c; + + scanf("%d %d %c", &a, &b, &c); + + double ans = a; + + if (b == 90) { + ans *= P90; + } else if (b == 93) { + ans *= P93; + } else { // b == 97 + ans *= P97; + } + + if (c == 'm') { + ans *= 0.95; + } else { // c == 'e' + ans *= 0.97; + } + + printf("%.2lf\n", ans); + + return 0; +} diff --git a/【实践课内】2.选择结构1/7-5 计算油费.jpg b/【实践课内】2.选择结构1/7-5 计算油费.jpg new file mode 100644 index 0000000..b742788 Binary files /dev/null and b/【实践课内】2.选择结构1/7-5 计算油费.jpg differ