|
发表于 2022-4-21 00:20:55
|
显示全部楼层
本帖最后由 SHthenew 于 2022-4-21 00:39 编辑
0. 10次
1. 没有
2. a, b, c
3. 13, 4, 9(答案:14, 5, 9)
4. int z = x >= 0 ? x : -x
5.
A.- if (size > 12)
- {
- cost = cost * 1.05;
- flag = 2;
- }
- bill = cost * flag;
复制代码
B.- if (ibex > 14)
- {
- sheds = 3;
- }
- sheds = 2;
- help = 2 * sheds;
复制代码
C.- if (score < 0)
- {
- printf("count = %d\n", count);
- }
- count++;
- scanf("%d", &score);
复制代码
0.- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int init_money = 10000, year = 1;
- _Bool is_beyond = 0;
- float a_rate = 0.1, b_rate = 0.05;
- float a_total, b_total;
- while (!is_beyond)
- {
- a_total = init_money * (1 + a_rate * year);
- b_total = init_money * pow((1 + b_rate), year);
- if (b_total > a_total)
- {
- is_beyond = 1;
- }
- else
- {
- year++;
- }
- }
- printf("%d年后,b的投资额超过a!\n", year);
- printf("a的投资额是:%.2f\n", a_total);
- printf("b的投资额是:%.2f\n", b_total);
- return 0;
- }
复制代码
1.- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int year = 0;
- _Bool isBreak = 0;
- float remainMoney = 4000000, rate = 0.08;
- while (!isBreak)
- {
- if (remainMoney > 0)
- {
- remainMoney = (remainMoney - 500000) * (1 + rate);
- year++;
- }
- else
- {
- isBreak = 1;
- }
-
- }
-
- printf("%d年后,我败光所有家产,再次回到一贫如洗……\n", year);
- return 0;
- }
复制代码
2.- #include <stdio.h>
- #include <math.h>
- int main()
- {
- double max = pow(10, -8), pi, temp, result;
- for (int i = 1; 1.0 / (2 * i - 1) > max; i++)
- {
- temp = i % 2 ? 1.0 / (2 * i - 1) : -(1.0 / (2 * i -1));
- result += temp;
- }
- pi = 4 * result;
- printf("pi的值为%.7f\n", pi);
-
- return 0;
- }
复制代码
3.- #include <stdio.h>
- int cacu(month)
- {
- if (month == 0)
- {
- return 0;
- }
- else if (month == 1)
- {
- return 1;
- }
- else
- {
- return cacu(month - 1) + cacu(month - 2);
- }
-
- }
- int main()
- {
- int result = cacu(24);
- printf("2年后一共有%d对兔子\n", result);
- return 0;
- }
复制代码 |
|