鱼C论坛

 找回密码
 立即注册
楼主: 小甲鱼

[课后作业] S1E16:拾遗 | 课后测试题及答案

  [复制链接]
发表于 2026-4-15 04:04:47 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
  1. //利息计算
  2. //启动资金10000
  3. //固定利息 = 本金*0.1%
  4. //复合利息 = (本金+产生的利息)*0.05%
  5. #include<stdio.h>
  6. int main()
  7. {
  8.         float a = 10000;
  9.         float b = 10000;
  10.         int count = 0;
  11.         float ra = a * 0.1;

  12.         do
  13.         {
  14.                 a += ra;                        //固定利息
  15.                 b += (b * 0.05);        //复利
  16.                 count++;
  17.         } while (b < a);

  18.         printf("%d 年后, 黑夜的投资额超过小甲鱼!\n", count);
  19.         printf("小甲鱼的投资额是: %.2f\n", a);
  20.         printf("  黑夜的投资额是: %.2f\n", b);
  21.         return 0;
  22. }





  23. //本金400万   每年0.08利息   每年开支50万   算几年后破产
  24. #include<stdio.h>
  25. int main()
  26. {
  27.         float a = 4000000;
  28.         int count = 0;
  29.         while (a > 0)
  30.         {
  31.                 a -= 500000;        //开销
  32.                 a += a * 0.08;        //利息
  33.                 count++;
  34.         }

  35.         printf("%d年后,小甲鱼败光了所有的家产,再次回到一贫如洗......", count);
  36.         return 0;
  37. }






  38. //计算 (pi) 的值
  39. #include<stdio.h>
  40. int main()
  41. {
  42.         double a = 0;
  43.         int flag = 1;

  44.         // (pi/4) = 1 - (1/3) + (1/5) - ...... + flag(1/n+2)
  45.         for (int i = 1; i < 100000000; i += 2)               
  46.         {
  47.                 a += 1.0 * flag / i;
  48.                 flag = -flag;
  49.         }

  50.         a *= 4.0;
  51.         printf("Pi = %.7lf", a);
  52.         return 0;
  53. }








  54. //兔子出生2个月后    每月可以生一对兔子    2年后(24个月)有多少兔子
  55. //斐波那契数列
  56. #include<stdio.h>
  57. int main()
  58. {
  59.         int f1 = 0;
  60.         int f2 = 1;
  61.         int f3 = 0;
  62.         int i = 0;
  63.         int count = 2;

  64.         printf("%d对(1月)\t", f2);
  65.         for (i = 2; i <= 24; i++, count++)
  66.         {
  67.                 f3 = f1 + f2;
  68.                 printf("%d对(%d月)\t", f3, count);

  69.                 //后移一位, 为下次循环做准备
  70.                 f1 = f2;
  71.                 f2 = f3;

  72.                 //换行 格式
  73.                 if (count % 6 == 0)
  74.                         printf("\n");
  75.         }
  76.         return 0;
  77. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-4-15 09:29:25 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-4-15 17:17:40 | 显示全部楼层
测试题:
0:10个,在内循环中的循环条件是j<10时循环,而最后j=10时内层循环退出,而外层循环的条件是需要j!=10,而此时j=10,外层循环也退出了.所以将打印10个'A'
1:0个,因为i++是先取出变量i的值,然后在自增1,那么第一次循环是while内的值是0,循环直接不执行.
2: a, b, c,都是lvalue.
3:a=14, b=5, c=9
4:z = x < 0 ? -x : x
5:
A:
  1. if (size > 12)
  2. {
  3. cost = cost * 1.05;
  4. flag = 2;
  5. }
  6. bill = cost * flag;
复制代码

B:
  1. if (ibex > 14)
  2. {
  3. sheds = 3;
  4. }else
  5. {
  6. sheds = 2;
  7. }
  8. help = 2 * sheds;
复制代码


c:
  1. scanf("%d", &score);
  2. while(score < 0)
  3. {
  4. count ++
  5. scanf("%d", &score);
  6. }
  7. printf("count = %d\n", count);
复制代码


动动手:
0:
  1. #include <stdbool.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>

  4. int main(int argc, char *argv[]) {
  5.   float xjysmoey = 10000, hysmoney = 10000;

  6.   int years = 1;
  7.   while (xjysmoey >= hysmoney) {

  8.     xjysmoey = 10000 + 10000 * years * 0.1;
  9.     hysmoney = hysmoney + hysmoney * 0.05;
  10.     years++;
  11.   }
  12.   printf("%d年后,黑夜的投资额超过小甲鱼!\n小甲鱼的投资额是:%."
  13.          "2f\n黑夜的投资额是:%.2f\n",
  14.          years - 1, xjysmoey, hysmoney);

  15.   return EXIT_SUCCESS;
  16. }
复制代码


1:
  1. #include <stdbool.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>

  4. int main(int argc, char *argv[]) {
  5.   float money = 4000000;
  6.   int years = 0;
  7.   while (money >= 0) {

  8.     money -= 500000;
  9.     money += money * 0.08;
  10.     years++;
  11.   }
  12.   printf("%d年之后,小甲鱼败光了所有的家产,再次回到一贫如洗......\n", years);
  13.   return EXIT_SUCCESS;
  14. }
复制代码

2:
  1. #include <math.h>
  2. #include <stdbool.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>

  5. int main(int argc, char *argv[]) {
  6.   double PI = 0.0, n = 1, term = 1.0; // PI 是圆周率  n是分母,term是该项的值;

  7.   int sign = 1; // sign代表正负值;

  8.   while (fabs(term) >= 1e-8) { // 1e-8 就是10 ^ (-8) 在程序中的表达式.
  9.     PI = PI + term;
  10.     sign = -sign;
  11.     n = n + 2;
  12.     term = sign / n;
  13.   }
  14.   PI = PI * 4;
  15.   printf("PI的值为:%15.7f\n", PI);

  16.   return EXIT_SUCCESS;
  17. }
复制代码


3:
  1. #include <stdbool.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>

  4. int main(int argc, char *argv[]) {
  5.   long a;

  6.   int month = 3;

  7.   int firstmonth, sencondmonth;
  8.   firstmonth = 1;
  9.   sencondmonth = 1;
  10.   while (month <= 24) {

  11.     a = firstmonth + sencondmonth;
  12.     sencondmonth = firstmonth;
  13.     firstmonth = a;

  14.     month++;
  15.   }

  16.   printf("%ld\n", a);
  17.   return EXIT_SUCCESS;
  18. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-4-16 18:41:33 | 显示全部楼层
10个A
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-5-9 22:13:57 | 显示全部楼层
尽力了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-6-4 20:54:24 | 显示全部楼层
本帖最后由 小正阿 于 2026-6-4 21:01 编辑

0. 10 个。

1. 0个。

2. 不清楚。

3.
a = 14
b = 5
c = 9
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-6-11 14:18:44 | 显示全部楼层
111
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-6-14 12:26:04 | 显示全部楼层
111
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-6-18 10:51:36 | 显示全部楼层
+1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-6-23 07:46:48 | 显示全部楼层

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-6-25 11:14:37 | 显示全部楼层
.
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-7-9 20:35:56 | 显示全部楼层
.
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-7-16 16:13:51 | 显示全部楼层
回复
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-7-20 22:07:37 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-7-27 11:54:32 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-7-27 19:13:43 | 显示全部楼层
答案
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-8-9 14:42:51 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-8-13 14:24:24 | 显示全部楼层
想看答案对一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-8-16 09:39:53 | 显示全部楼层
0.11个
1.9个
2.a,b,c均为左值?
3.a = 14,b = 5,c = 9//括号中最后一个结果赋值给a其中的4无意义
4.z = (x>0?a:-a)
5.A.
  1. if (size > 12)
  2. {
  3.         cost = cost*1.05;
  4.         flag = 2;
  5. }
  6. bill = cost*flag;
复制代码

B.
  1. if(ibex > 14)
  2. {
  3.         sheds = 3;
  4. }
  5. else
  6. {
  7.         sheds = 2;
  8. }
  9. help = 2 * sheds;
复制代码

C.
  1. int count = -1
  2. do
  3. {
  4.         scanf("%d",&score);
  5.         count ++;
  6. }
  7. while(score < 0);
  8. printf("count = %d\n",count);
复制代码

动动手0.
  1. #include <stdio.h>

  2. int main()
  3. {
  4.         double i,j;
  5.         i = j = 10000;
  6.         int count = 0;
  7.        
  8.         while(i <= j)
  9.         {
  10.                 i = i * 1.05;
  11.                 j = j + 1000;
  12.                 count ++;
  13.         }
  14.         printf("%d年后,黑夜的投资额超过小甲鱼!\n",count);
  15.         printf("小甲鱼的投资额是:%.2f\n",j);
  16.         printf("黑夜的投资额是:%.2f\n",i);

  17.     return 0;
  18. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-8-18 11:07:54 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-9-18 21:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表