1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-10-18 08:13:38 +00:00

【实践课内】2.选择结构1

This commit is contained in:
Baoshuo Ren 2024-10-18 16:13:01 +08:00
parent 887f488943
commit 5b0dfb811d
Failed to extract signature
10 changed files with 105 additions and 0 deletions

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 KiB

View 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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 KiB