|
发表于 2022-12-30 17:42:58
|
显示全部楼层
测试题:
0.erroy,因為for的表達式2的,不知是&&還是||
1.9次
2.a, b, c
3.a = 14, b = 5, c = 9
4.z = z >= 0? z: z*-1;
5.
A.
- if (size > 12)
- {
- cost = cost * 1.05;
- flog = 2;
- }
- else
- {
- bill = cost * flag;
- }
复制代码
B.
- if (ibex > 14)
- {
- sheds = 3;
- }
- else
- {
- sheds = 2;
- help = 2 * sheds;
- }
复制代码
C.
- _Bool state = 0;
- do
- {
- scanf("%d, &score");
- if (score < 0)
- {
- printf("count = %d\n", count);
- }
- else
- {
- state = 1;
- count++;
- }
- }while(!state);
复制代码
动动手:
0.
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- float fish = 10000, night = 10000;
- int count = 0;
- while (fish >= night)
- {
- fish = 10000;
- night = 10000;
- count++;
- fish = fish * (1 + 0.1 * count);
- night = night * pow((1 + 0.05), count);
- }
- printf("%d year later, night will over the fish!\n", count);
- printf("fish: %.2f\n", fish);
- printf("night: %.2f\n", night);
- return 0;
- }
复制代码
1.
- #include <stdio.h>
- int main()
- {
- float fish = 4000000;
- int count = 0;
- while (fish >= 0)
- {
- fish -= 500000;
- fish *= (1 + 0.08);
- count++;
- }
- printf("%d year later, fish no money\n", count);
- return 0;
- }
复制代码
2.
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- float pi = 1, j = -1.0;
- int num = 3, i;
- for (i = 0; i < 1000000000; i++)
- {
- pi += j / num;
- num += 2;
- j = -j;
- }
- pi *= 4;
- printf("%.7f\n", pi);
- return 0;
- }
复制代码
3.
- #include <stdio.h>
- int main()
- {
- int a, b, c, month;
- a = 1;
- b = 1;
- for (month = 2; month >= 24; month++)
- {
- c = a + b;
- a = b;
- b = c;
- }
- printf("%d\n", c);
- return 0;
- }
复制代码
32767隻 |
|