mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-08 11:08:41 +00:00
【额外练习】选择结构
This commit is contained in:
parent
01f72aa8a0
commit
febf51beea
17
【额外练习】选择结构/7-39 选择-矩形切割.c
Normal file
17
【额外练习】选择结构/7-39 选择-矩形切割.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
double a, b, m, n;
|
||||
|
||||
scanf("%lf%lf%lf%lf", &a, &b, &m, &n);
|
||||
|
||||
if (m == a && n == b) {
|
||||
printf("3\n");
|
||||
} else if (m == a || n == b) {
|
||||
printf("4\n");
|
||||
} else {
|
||||
printf("5\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
24
【额外练习】选择结构/7-40 选择-工资计算.c
Normal file
24
【额外练习】选择结构/7-40 选择-工资计算.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int year;
|
||||
double time;
|
||||
|
||||
scanf("%d%lf", &year, &time);
|
||||
|
||||
if (year >= 5) {
|
||||
if (time <= 40) {
|
||||
printf("%.2lf\n", time * 50);
|
||||
} else {
|
||||
printf("%.2lf\n", 40 * 50 + (time - 40) * 50 * 1.5);
|
||||
}
|
||||
} else {
|
||||
if (time <= 40) {
|
||||
printf("%.2lf\n", time * 30);
|
||||
} else {
|
||||
printf("%.2lf\n", 40 * 30 + (time - 40) * 30 * 1.5);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
22
【额外练习】选择结构/7-41 选择-完全平方数2.c
Normal file
22
【额外练习】选择结构/7-41 选择-完全平方数2.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
int x = sqrt(n);
|
||||
|
||||
if (x * x == n) {
|
||||
if (x % 2 == 0) {
|
||||
printf("Even special number\n");
|
||||
} else {
|
||||
printf("Odd special number\n");
|
||||
}
|
||||
} else {
|
||||
printf("No\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user