【额外练习】选择结构
15
【额外练习】选择结构/7-1 选择-孔融让梨.c
Normal 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;
|
||||
}
|
BIN
【额外练习】选择结构/7-1 选择-孔融让梨.jpg
Normal file
After Width: | Height: | Size: 325 KiB |
15
【额外练习】选择结构/7-2 选择-奇偶判断.c
Normal 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;
|
||||
}
|
BIN
【额外练习】选择结构/7-2 选择-奇偶判断.jpg
Normal file
After Width: | Height: | Size: 262 KiB |
15
【额外练习】选择结构/7-3 选择-ASCII值.c
Normal 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;
|
||||
}
|
BIN
【额外练习】选择结构/7-3 选择-ASCII值.jpg
Normal file
After Width: | Height: | Size: 298 KiB |
15
【额外练习】选择结构/7-4 选择-闰年.c
Normal 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;
|
||||
}
|
BIN
【额外练习】选择结构/7-4 选择-闰年.jpg
Normal file
After Width: | Height: | Size: 259 KiB |
15
【额外练习】选择结构/7-5 选择-排序.c
Normal 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;
|
||||
}
|
BIN
【额外练习】选择结构/7-5 选择-排序.jpg
Normal file
After Width: | Height: | Size: 262 KiB |
18
【额外练习】选择结构/7-6 选择-分段函数3.c
Normal 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;
|
||||
}
|
BIN
【额外练习】选择结构/7-6 选择-分段函数3.jpg
Normal file
After Width: | Height: | Size: 260 KiB |
18
【额外练习】选择结构/7-7 选择-圆塔.c
Normal 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;
|
||||
}
|
BIN
【额外练习】选择结构/7-7 选择-圆塔.jpg
Normal file
After Width: | Height: | Size: 308 KiB |