鱼C论坛

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

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

  [复制链接]
发表于 2021-4-26 14:46:43 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-26 14:49:41 | 显示全部楼层
16
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-26 16:28:19 | 显示全部楼层
第0题:100次
第1题:9次
第2题:不知道
第3题:a=17,b=6,c=17
第4题:z=x>=0?x:-x
第5题:
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-4-26 19:29:50 | 显示全部楼层
1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-26 20:30:38 | 显示全部楼层
111
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-26 22:40:21 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-27 00:35:37 | 显示全部楼层
测试题
0. 10 个
1. 不打印 B
2. a、b、c 都是
3. a = 14,b = 5,c = 9
4.
  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.         int x, z;

  5.         printf("请输入一个整数:");
  6.         scanf("%d", &x);

  7.         if (x >= 0) {
  8.                 z = x;
  9.         } else {
  10.                 z = -x;
  11.         }

  12.         printf("%d 的绝对值是:%d\n", x, z);

  13.         return 0;
  14. }
复制代码

5
A.
  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.         int size, flag = 1;
  5.         float cost = 1.0, bill = 0.0;

  6.         printf("请输入size:");
  7.         scanf("%d", &size);

  8.         // 带 goto 版本
  9.         if (size > 12) {
  10.                 goto a;
  11.         }
  12.         goto b;
  13. a:        cost = cost * 1.05;
  14.         flag = 2;
  15. b:        bill = cost * flag;
  16.         printf("带 goto 版本:cost = %f, flag = %d, bill = %f\n", cost, flag, bill);
  17.        
  18.         cost = 1, flag = 1, bill = 0;
  19.         // 不带 goto 版本
  20.         if (size > 12) {
  21.                 cost = cost * 1.05;
  22.                 flag = 2;
  23.         }
  24.         bill = cost * flag;
  25.         printf("不带 goto 版本:cost = %f, flag = %d, bill = %f\n", cost, flag, bill);


  26.         return 0;
  27. }
复制代码

B.
  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.         int ibex, sheds, help;

  5.         printf("请输入ibex:");
  6.         scanf("%d", &ibex);

  7.         // 带 goto 版本
  8.         if (ibex > 14) {
  9.                 goto a;
  10.         }
  11.         sheds = 2;
  12.         goto b;
  13. a:        sheds = 3;
  14. b:        help = 2 * sheds;
  15.         printf("help = %d\n", help);

  16.         // 不带 goto 版本
  17.         if (ibex > 14) {
  18.                 sheds = 3;
  19.         } else {
  20.                 sheds = 2;
  21.         }
  22.         help = 2 * sheds;
  23.         printf("help = %d\n", help);

  24.         return 0;
  25. }
复制代码

C
  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.         int score, count = 0;

  5.         // 带goto版本
  6. readin:        scanf("%d", &score);
  7.         if (score < 0) {
  8.                 goto stage2;
  9.         }
  10.         count ++;
  11.         goto readin;
  12. stage2:        printf("count = %d\n", count);

  13.         // 不带goto版本
  14.         count = 0;
  15.         while (scanf("%d", &score), !(score < 0)) {
  16.                 count++;
  17.         }
  18.         printf("count = %d\n", count);

  19.         return 0;
  20. }
复制代码

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

  2. int main(void)
  3. {
  4.         float x_money = 10000.0, h_money = 10000.0;
  5.         int years = 0;

  6.         while (x_money >= h_money)
  7.         {
  8.                 years++;
  9.                 x_money += 10000.0 * 0.1;
  10.                 h_money *= 1.05;
  11.         }
  12.         printf("%d年后,黑夜的投资额超过小甲鱼!\n", years);
  13.         printf("小甲鱼的投资额是:%.2f\n", x_money);
  14.         printf("黑夜的投资额是:%.2f\n", h_money);

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

1.
  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.         float money = 4000000.0;
  5.         int years = 0;

  6.         while (money > 0) {
  7.                 years++;
  8.                 money -= 500000.0;
  9.                 money *= 1.08;
  10.         }
  11.         printf("%d年后,笑甲鱼败光了所有的家产,再次回到一贫如洗……\n", years);

  12.         return 0;
  13. }
复制代码

2.
  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.         double item, quarter_pi;
  5.         int num, sign;

  6.         for (num = 1, sign = 1; (item = 1.0 / num) >= 1e-8; num += 2, sign = -sign) {
  7.                 quarter_pi += sign * item;
  8.         }

  9.         printf("Pi小数点后前7位为:%.7f\n", quarter_pi * 4);

  10.         return 0;
  11. }
复制代码

3.
  1. #include <stdio.h>

  2. int main(void)
  3. {
  4.         int f_1 = 1, f_2 = 1, cur, month;

  5.         for (month = 22; month > 0; month -= 1) {
  6.                 cur = f_1 + f_2;
  7.                 f_1 = f_2;
  8.                 f_2 = cur;
  9.         }

  10.         printf("两年后的兔子总计%d对\n", cur);

  11.         return 0;
  12. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-4-27 17:53:55 | 显示全部楼层
查看答案
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-4-27 20:07:42 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-27 20:10:41 | 显示全部楼层
check
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-4-27 20:32:52 | 显示全部楼层
我有个朋友
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-4-27 21:32:00 | 显示全部楼层
查看
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-27 22:01:27 | 显示全部楼层
查看
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-4-27 23:27:50 | 显示全部楼层
0、100
1、9
2、(a = b = c)
3、a =14  ,b = 5,c = 9
4、
  1. #include <stdio.h>

  2. int main()
  3. {
  4.         int x, z;
  5.        
  6.         printf("请输入数字(求绝对值):");
  7.         scanf("%d", &x);
  8.        
  9.         if(x >= 0)
  10.         {
  11.                 z = x;
  12.         }
  13.         else
  14.         {
  15.                 z = x * (-1);
  16.         }
  17.        
  18.         printf("绝对值为:%d", z);

  19.     return 0;
  20. }
复制代码

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.         shed = 2;
  6.         help = 2 * sheds;
复制代码

C、
while(1)
        {
                scanf("%d", &score);
               
                if(score < 0)
                {
                        printf("count = %d\n", count);
                }
                count++;               
        }
动动手:
0、
  1. #include <stdio.h>

  2. int main()
  3. {
  4.         float x, h; //x表示小甲鱼所拥有的钱,h表示黑夜所拥有的钱
  5.         int count = 0;
  6.        
  7.         x = h = 10000;
  8.        
  9.         while(x >= h)
  10.         {
  11.                 x = x + 10000 * 0.1;
  12.                 h = h + h * 0.05;
  13.                 count++;
  14.         }
  15.        
  16.         printf("%d年后,黑夜的投资额超过小甲鱼。\n");
  17.         printf("小甲鱼的投资额是:%.2f\n", x);
  18.         printf("黑夜的投资额是:%.2f\n", h);
  19.        
  20.     return 0;       
  21. }
复制代码

1、
  1. #include <stdio.h>

  2. int main()
  3. {
  4.         float money = 4000000;
  5.         int count = 0;
  6.        
  7.         while(money >= 0)
  8.         {
  9.                 money = money - 500000;
  10.                 money = money + money * 0.08;
  11.                 count++;
  12.         }
  13.        
  14.         printf("%d年之后,小甲鱼败光了所有的家产,再次回到一贫如洗....", count);
  15.        
  16.         return 0;
  17. }
复制代码

2、
  1. #include <stdio.h>
  2. #include <math.h>

  3. int main()
  4. {
  5.         float result = 0;
  6.         float i = 1;
  7.         int count = 1;
  8.        
  9.         while(fabs((1 / i)) > pow(10, -7))
  10.         {
  11.                 result = result + (1 / i * count);
  12.                 count = -count;
  13.                 i = i + 2;
  14.         }
  15.        
  16.         printf("Pi的近似值为%.7f", 4 * result);
  17.        
  18.         return 0;
  19. }
复制代码

3、

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-4-28 23:25:21 | 显示全部楼层
0、 10
1、 0个
2、 a
3、 14,5,9
4、 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;
}
else
{
    sheds = 2;
}
help = 2 * sheds;

C、
do
{
    scanf("%d", &score);
    if(score < 0)
    {break;}
    count++;
}while(1);
printf("count = %d\n", count);

动动手:
0、
    1 #include <stdio.h>                                                            
    2                                                                          
    3 #define BENJIN 10000                                                              
    4 #define DLTZ 0.1                                                              
    5 #define FHLX 0.05                                                        
    6                                                                                            
    7 int main(void)                                                                             
    8 {                                                                  
    9         double xjy=BENJIN, hy=BENJIN;                                                
   10         int n=0;                                                   
   11         while(xjy >= hy)                                                      
   12         {                                                                     
   13                 xjy = xjy + BENJIN * DLTZ;                                                
   14                 hy = hy + hy * FHLX;                                                      
   15                 n++;                                                                       
   16         }                                                                                 
   17         printf("%d年后,黑夜的投资额超过小甲鱼!\n", n);                                   
   18         printf("小甲鱼的投资额是:%.2lf\n", xjy);                                          
   19         printf("黑夜的投资额是:%.2lf\n", hy);                                             
   20                                                         
   21         return 0;                                                                        
   22 }

1、  
    1 #include <stdio.h>
    2
    3
    4 #define BENJIN 4000000
    5 #define DLTZ 0.08
    6
    7 int main(void)
    8 {
    9         double xjy=BENJIN;
   10         int n=0;
   11         while(xjy > 0)
   12         {
   13                 xjy -= 500000;
   14                 xjy = xjy + xjy * DLTZ;
   15                 
   16                 n++;
   17         }
   18         printf("%d年后,小甲鱼败光了所有的家产,再次一贫如洗……\n", n);
   19
   20         return 0;
   21 }

2、
    1 #include <stdio.h>                                                                        
    2 #include <math.h>                                                                        
    3                                                                                          
    4 int main(void)                                                                           
    5 {                                                                                         
    6         int n=1;                                                                          
    7         double pi = 1, i = 1;                                                            
    8         do                                                                                 
    9         {                                                                                 
   10                 i = -i;                                                                    
   11                 n += 2;                                                                  
   12                 pi = pi + i / n;                                                           
   13         }while (fabs(i/n) >= pow(10, -8));                                                
   14         pi = 4 * pi;                                                                     
   15         printf("PI = :%.7lf", pi);                                                        
   16                                                                                          
   17         return 0;                                                            
   18 }      

3、
46368对

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-4-30 16:10:45 | 显示全部楼层
查看答案
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-5-1 15:26:09 | 显示全部楼层
1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-5-1 16:00:27 | 显示全部楼层
1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-5-3 11:56:35 | 显示全部楼层
8
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-5-3 20:29:41 | 显示全部楼层
1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-7 08:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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