diff --git a/【额外练习】选择结构/7-1 选择-孔融让梨.c b/【额外练习】选择结构/7-1 选择-孔融让梨.c new file mode 100644 index 0000000..b71b18e --- /dev/null +++ b/【额外练习】选择结构/7-1 选择-孔融让梨.c @@ -0,0 +1,15 @@ +#include + +int main() { + int a, b; + + scanf("%d%d", &a, &b); + + if (a < b) { + printf("%d\n", a); + } else { + printf("%d\n", b); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-1 选择-孔融让梨.jpg b/【额外练习】选择结构/7-1 选择-孔融让梨.jpg new file mode 100644 index 0000000..0861621 Binary files /dev/null and b/【额外练习】选择结构/7-1 选择-孔融让梨.jpg differ diff --git a/【额外练习】选择结构/7-2 选择-奇偶判断.c b/【额外练习】选择结构/7-2 选择-奇偶判断.c new file mode 100644 index 0000000..0588bac --- /dev/null +++ b/【额外练习】选择结构/7-2 选择-奇偶判断.c @@ -0,0 +1,15 @@ +#include + +int main() { + int a; + + scanf("%d", &a); + + if (a % 2 == 1) { + printf("YES\n"); + } else { + printf("NO\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-2 选择-奇偶判断.jpg b/【额外练习】选择结构/7-2 选择-奇偶判断.jpg new file mode 100644 index 0000000..cfe7a64 Binary files /dev/null and b/【额外练习】选择结构/7-2 选择-奇偶判断.jpg differ diff --git a/【额外练习】选择结构/7-3 选择-ASCII值.c b/【额外练习】选择结构/7-3 选择-ASCII值.c new file mode 100644 index 0000000..59a9984 --- /dev/null +++ b/【额外练习】选择结构/7-3 选择-ASCII值.c @@ -0,0 +1,15 @@ +#include + +int main() { + char c; + + scanf("%c", &c); + + if ('0' <= c && c <= '9') { + printf("%d\n", c); + } else { + printf("input error\n"); + } + + return 0; +} diff --git a/【额外练习】选择结构/7-3 选择-ASCII值.jpg b/【额外练习】选择结构/7-3 选择-ASCII值.jpg new file mode 100644 index 0000000..532a549 Binary files /dev/null and b/【额外练习】选择结构/7-3 选择-ASCII值.jpg differ diff --git a/【额外练习】选择结构/7-4 选择-闰年.c b/【额外练习】选择结构/7-4 选择-闰年.c new file mode 100644 index 0000000..b9ce518 --- /dev/null +++ b/【额外练习】选择结构/7-4 选择-闰年.c @@ -0,0 +1,15 @@ +#include + +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; +} diff --git a/【额外练习】选择结构/7-4 选择-闰年.jpg b/【额外练习】选择结构/7-4 选择-闰年.jpg new file mode 100644 index 0000000..167bca5 Binary files /dev/null and b/【额外练习】选择结构/7-4 选择-闰年.jpg differ diff --git a/【额外练习】选择结构/7-5 选择-排序.c b/【额外练习】选择结构/7-5 选择-排序.c new file mode 100644 index 0000000..6ff353d --- /dev/null +++ b/【额外练习】选择结构/7-5 选择-排序.c @@ -0,0 +1,15 @@ +#include + +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; +} diff --git a/【额外练习】选择结构/7-5 选择-排序.jpg b/【额外练习】选择结构/7-5 选择-排序.jpg new file mode 100644 index 0000000..39f1741 Binary files /dev/null and b/【额外练习】选择结构/7-5 选择-排序.jpg differ diff --git a/【额外练习】选择结构/7-6 选择-分段函数3.c b/【额外练习】选择结构/7-6 选择-分段函数3.c new file mode 100644 index 0000000..b46b343 --- /dev/null +++ b/【额外练习】选择结构/7-6 选择-分段函数3.c @@ -0,0 +1,18 @@ +#include +#include + +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; +} diff --git a/【额外练习】选择结构/7-6 选择-分段函数3.jpg b/【额外练习】选择结构/7-6 选择-分段函数3.jpg new file mode 100644 index 0000000..5326377 Binary files /dev/null and b/【额外练习】选择结构/7-6 选择-分段函数3.jpg differ diff --git a/【额外练习】选择结构/7-7 选择-圆塔.c b/【额外练习】选择结构/7-7 选择-圆塔.c new file mode 100644 index 0000000..8d7d440 --- /dev/null +++ b/【额外练习】选择结构/7-7 选择-圆塔.c @@ -0,0 +1,18 @@ +#include + +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; +} diff --git a/【额外练习】选择结构/7-7 选择-圆塔.jpg b/【额外练习】选择结构/7-7 选择-圆塔.jpg new file mode 100644 index 0000000..43a4a13 Binary files /dev/null and b/【额外练习】选择结构/7-7 选择-圆塔.jpg differ