mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-23 15:48:42 +00:00
【实践课内】2.选择结构1
This commit is contained in:
parent
887f488943
commit
5b0dfb811d
15
【实践课内】2.选择结构1/7-1 整数绝对值.c
Normal file
15
【实践课内】2.选择结构1/7-1 整数绝对值.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x;
|
||||
|
||||
scanf("%d", &x);
|
||||
|
||||
if (x < 0) {
|
||||
printf("%d\n", -x);
|
||||
} else {
|
||||
printf("%d\n", x);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课内】2.选择结构1/7-1 整数绝对值.jpg
Normal file
BIN
【实践课内】2.选择结构1/7-1 整数绝对值.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 233 KiB |
17
【实践课内】2.选择结构1/7-2 偶数乘2奇数乘3.c
Normal file
17
【实践课内】2.选择结构1/7-2 偶数乘2奇数乘3.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int x;
|
||||
|
||||
scanf("%d", &x);
|
||||
|
||||
if (x % 2 == 0) {
|
||||
x *= 2;
|
||||
} else {
|
||||
x *= 3;
|
||||
}
|
||||
|
||||
printf("y=%d\n", x);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课内】2.选择结构1/7-2 偶数乘2奇数乘3.jpg
Normal file
BIN
【实践课内】2.选择结构1/7-2 偶数乘2奇数乘3.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 292 KiB |
17
【实践课内】2.选择结构1/7-3 成绩判定.c
Normal file
17
【实践课内】2.选择结构1/7-3 成绩判定.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
【实践课内】2.选择结构1/7-3 成绩判定.jpg
Normal file
BIN
【实践课内】2.选择结构1/7-3 成绩判定.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 317 KiB |
24
【实践课内】2.选择结构1/7-4 选择-计算器2.c
Normal file
24
【实践课内】2.选择结构1/7-4 选择-计算器2.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
【实践课内】2.选择结构1/7-4 选择-计算器2.jpg
Normal file
BIN
【实践课内】2.选择结构1/7-4 选择-计算器2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 357 KiB |
32
【实践课内】2.选择结构1/7-5 计算油费.c
Normal file
32
【实践课内】2.选择结构1/7-5 计算油费.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
【实践课内】2.选择结构1/7-5 计算油费.jpg
Normal file
BIN
【实践课内】2.选择结构1/7-5 计算油费.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 335 KiB |
Loading…
Reference in New Issue
Block a user