鱼C论坛

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

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

  [复制链接]
发表于 2026-3-7 00:14:59 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

使用道具 举报

发表于 2026-3-12 15:30:49 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-3-13 19:52:01 | 显示全部楼层
0.10个A,逗号运算符的结果看最后一个运算表达式
1.会打印0个B,第一次判断的时候就跳出循环了
2.a,b,c
3.a=9,b=5,c=4
4.z = x>=0 ? x : -x;
5.
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-3-19 14:34:12 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-3-23 15:07:35 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-3-28 16:48:02 | 显示全部楼层
4
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-3-28 16:57:14 | 显示全部楼层
查看参考答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-3-30 20:45:17 | 显示全部楼层
jj'
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-4-1 23:15:45 | 显示全部楼层
10个
10个
c b a
15 4 10
z =abs(x)
if (size > 12)
{
      cost *=1.05

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

使用道具 举报

发表于 2026-4-3 09:34:29 | 显示全部楼层
本帖为密码帖 ,请输入密码 
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

使用道具 举报

发表于 2026-4-7 21:28:17 | 显示全部楼层
0. 10
1. 0
2. a,b,c
3. c = 10 b=5 a = 15
4. 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);


#include<stdio.h>
void test00(){
    int touzie = 10000;
    double danlilv = 0.1;
    double fuhelilv = 0.05;
    int year = 0;
    double sum1 = touzie;
    double sum2 = touzie;
    while(sum1 >= sum2){
        sum1 += touzie * danlilv;
        printf("第%d年,单利总金额:%.2lf\n", year, sum1);
        sum2 += sum2 * fuhelilv;
        printf("第%d年,复利总金额:%.2lf\n", year, sum2);
        year++;
    }
    printf("年数:%d\n", year);
}

void test01(){
    double zonge = 4000000;
    double hongli = 0.08;
    int year = 0;
    while(zonge>=0){
        zonge -= 500000;
        zonge += zonge * hongli;
        year++;
    }
    printf("年数:%d\n", year);
}

void test02(){
    double pai = 0;
    int fenmu = 1;
    int fuhao = 1;
    double weixiang = 1;
    while(weixiang > 10E-8){
        weixiang = (double)1.0 / fenmu;
        pai += weixiang * fuhao;
        fuhao = -fuhao;
        fenmu += 2;
    }
    printf("pai的值为:%.10lf\n", pai*4);
}

void test03(){
    int sum = 2;
    for(int i=0; i<24; i++){
        sum *=2;
    }
    printf("sum的值为:%d\n", sum);
}

int main(){
    //test00();
    //test01();
    //test02();
    test03();
    return 0;
}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-4-10 09:02:34 | 显示全部楼层
屏幕截图 2026-04-10 090130.png 屏幕截图 2026-04-10 090147.png 屏幕截图 2026-04-10 090155.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-4-12 11:41:58 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

使用道具 举报

发表于 2026-4-15 02:44:03 | 显示全部楼层
  1. 0. 请问下边代码将打印多少个 'A'
  2. i (0~9)    j (0~9)
  3. 100次(外层10次 * 内层10次)



  4. 1. 请问下边代码会打印多少个 'B'
  5. i (0~10)
  6. 11次 (goto条件  i>10)


  7. 2. 请写出表达式 a = b = c = 5 中的"l-value"?
  8. a=(b=(c=5));      赋值(=)是右结合性     a是最后的左值



  9. 3. 请问表达式 a = (b = 3, 4, c = b++ + 5, ++c + ++b); 执行后,整型变量 a、b、c 的值是?
  10. b=3         c=b++ +5
  11. c = 8 (3+5)       b = 4 (3+1)

  12. (c+1) + (b+1)
  13. a = 14 (9+5)




  14. 4. 请使用条件运算符求出变量 x 的绝对值,并存放到变量 z 中
  15. z = (x > 0 ? x : -x);




  16. 5. C 语言其实在大部分情况下不使用 goto 语句也能做得很好
  17. 请尝试将下列代码段写成不带 goto 语句的版本

  18. 【1】
  19. if (size > 12)
  20. {
  21.         cost = cost * 1.05;
  22.         flag = 2;
  23. }
  24. bill = cost * flag;



  25. 【2】
  26. if (ibex > 14)
  27. {
  28.         sheds = 3;
  29.         help = 2 * sheds;
  30. }
  31. sheds = 2;
  32. help = 2 * sheds;



  33. 【3】
  34. do
  35. {
  36.         scanf("%d", &score);
  37.         count++;
  38. }
  39. while(score > 0)
  40. printf("count = %d\n", count);
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-4-15 04:04:47 | 显示全部楼层
  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
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-5-24 17:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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