1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 09:38:42 +00:00

【额外练习】选择结构

This commit is contained in:
Baoshuo Ren 2024-10-30 22:11:36 +08:00
parent 012b17b867
commit e2d637b4af
Failed to extract signature
14 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
int a, b;
scanf("%d%d", &a, &b);
if (a < b) {
printf("%d\n", a);
} else {
printf("%d\n", b);
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 KiB

View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
int a;
scanf("%d", &a);
if (a % 2 == 1) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
char c;
scanf("%c", &c);
if ('0' <= c && c <= '9') {
printf("%d\n", c);
} else {
printf("input error\n");
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB

View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
int year;
scanf("%d", &year);
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
double a, b;
scanf("%lf%lf", &a, &b);
if (a > b) {
printf("%.3lf %.3lf\n", a, b);
} else {
printf("%.3lf %.3lf\n", b, a);
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 KiB

View File

@ -0,0 +1,18 @@
#include <math.h>
#include <stdio.h>
int main() {
double x;
scanf("%lf", &x);
if (x < 1) {
printf("%.3lf\n", x);
} else if (1 <= x && x < 10) {
printf("%.3lf\n", sqrt(x * 2 - 1));
} else { // x >= 10
printf("%.3lf\n", log(x * 3 - 11));
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 KiB

View File

@ -0,0 +1,18 @@
#include <stdio.h>
int main() {
double x, y;
scanf("%lf%lf", &x, &y);
if ((x - 2) * (x - 2) + (y - 2) * (y - 2) <= 1
|| (x + 2) * (x + 2) + (y - 2) * (y - 2) <= 1
|| (x + 2) * (x + 2) + (y + 2) * (y + 2) <= 1
|| (x - 2) * (x - 2) + (y + 2) * (y + 2) <= 1) {
printf("10\n");
} else {
printf("0\n");
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 KiB