鱼C论坛

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

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

  [复制链接]
发表于 2020-8-27 15:53:09 | 显示全部楼层
零基础入门学习C语言封面
《零基础入门学习C语言》
小甲鱼 著
立即购买
0. 100
1. 10
2. a
3. a = 14, b = 5, c = 9
4.
  1.         x >= 0 ? z = x : z = -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. }
  5. sheds = 2;
  6. help = 2 * sheds;
复制代码

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


0.
  1. #include<stdio.h>

  2. int main()
  3. {
  4.         int year;
  5.         float jiayu = 10000, heiye = 10000;
  6.        
  7.         while(jiayu >= heiye)
  8.         {
  9.                 jiayu += 10000 * 0.1;
  10.                 heiye += heiye * 0.05;
  11.                 year++;
  12.         }
  13.        
  14.         printf("%d年后,黑夜的投资额超过小甲鱼!\n", year);
  15.         printf("小甲鱼的投资额是:%.2f\n", jiayu);
  16.         printf("黑夜的投资额是:%.2f\n", heiye);
  17.         return 0;
  18. }
复制代码


1.
  1. #include<stdio.h>

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


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

使用道具 举报

发表于 2020-8-27 16:48:24 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-27 20:45:04 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-27 21:44:13 | 显示全部楼层
0.10次
1.0次
2.a、b、c
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. }
  5. sheds = 2;
  6. help = 2 * sheds;
复制代码

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

动动手:
0.
  1. #include <stdio.h>
  2. int main()
  3. {
  4.         float jiayu = 10000, heiye = 10000;
  5.         int counter = 0;
  6.         do{
  7.                 counter++;
  8.                 jiayu += 10000*0.1;
  9.                 heiye *= 1.05;
  10.         }while(heiye<jiayu);
  11.         printf("%d年之后,黑夜的钱超过小甲鱼!\n", counter);
  12.         printf("小甲鱼的投资额是:%.2f\n", jiayu);
  13.         printf("黑夜的投资额是:%.2f\n", heiye);
  14.         return 0;}
复制代码

1.
  1. #include <stdio.h>
  2. #define fr_blion 4000000
  3. #define _50w 500000
  4. int main()
  5. {
  6.         int i = 1, _400w = fr_blion;
  7.         for(_400w -= _50w; _400w > 0; _400w -= _50w, ++i){
  8.                 _400w *= 1.08;
  9.         }
  10.         printf("%d年之后,小甲鱼败光所有家产,再次回到一贫如洗", i);
  11.         return 0;
  12. }
复制代码

2.
  1. #include <stdio.h>
  2. int main()
  3. {
  4.         int j;
  5.         float i,pi = 1, k;
  6.         for( i = 3, j = 2; (1/i)> 10e-8;++j, i = i +2 ){
  7.                 if(j % 2 == 0)
  8.                 k = -1/i;
  9.                 else k = 1/i;
  10.                 pi += k;
  11.         }printf("pi = %.7f", 4*pi);
  12.         return 0;}
复制代码

3.
  1. #include <stdio.h>
  2. int main(void){
  3. printf("不会");
  4. return 0;}
复制代码


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

使用道具 举报

发表于 2020-8-27 22:39:49 | 显示全部楼层
6
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-28 09:45:28 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-28 10:34:02 | 显示全部楼层
修改
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-28 12:06:47 | 显示全部楼层
K
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-28 14:41:35 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-29 15:34:51 | 显示全部楼层
学习了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-29 17:51:14 | 显示全部楼层
ccccccccccccccccccccccccccccccccccccccc
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-30 11:53:31 | 显示全部楼层
对答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-30 12:09:45 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-30 16:22:20 | 显示全部楼层
那个利率不应该是怎么表达的吗?为什么我是两年
int year=0;
float hy = 10000;
...
year++;
xjy = 10000 + (year*10000*0.);
hy = hy + (hy*0.05);

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

使用道具 举报

发表于 2020-8-30 16:30:07 | 显示全部楼层
855555555
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-31 01:26:10 | 显示全部楼层
10,10,4,9,16
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-31 21:02:43 | 显示全部楼层
测试:
0.很多个A,无法满足判断条件。
1.10次,进入while语句的时候先执行i++,这样的话if就判断了11次,打印了10个B
2.a,b,c;a,b,c均为变量,得到右边5的赋值。
3.a=14,b=4,c=10
4.x >= 0 ? z = x, z = -x;
5.
A.
if (size > 12)
{
       cost = cost * 1.05;
       flag = 2;
       continue;
}
     bill = cost * flag;
B.
if (ibex > 14)
{
        sheds = 3;
        continue;
}
sheds = 2;
help = 2 * sheds;
C.
while(1)
    {
        scanf("%d", &score);
        if (score < 0)
        {
            printf("count = %d\n", count);
            break;
        }
        count++;

    }
动动手:
0.
#include <stdio.h>
#include <math.h>
#define MONEY_FISH 10000 //定义小甲鱼和黑夜初始资金
#define MONEY_BLACK_NIGHT 10000
#define M_F_I 0.1//分别定义二者的单利息与复合利息
#define M_B_N_I 0.05

int main()
{
    float M_F,M_B_N;//定义小甲鱼和黑夜的投资额所代表的自变量
    int year;//黑夜投资额超过小甲鱼所需要的年限

    for(year = 0,M_B_N = MONEY_BLACK_NIGHT,M_F = MONEY_FISH;M_B_N <= M_F;year++)
    {
        M_B_N *= (1+M_B_N_I) ;
        M_F += MONEY_FISH * M_F_I;
    }

    printf("%d年后,黑夜的投资额超过小甲鱼!\n",year);
    printf("小甲鱼的投资额是:%.2f\n",M_F);
    printf("黑夜的投资额是:%.2f\n",M_B_N);
    return 0;
}
1.
#include <stdio.h>
#define F_M 4000000 //定义小甲鱼的初始资金
#define F_COST 500000//小甲鱼一年开销
#define interst 0.08//红利

int main()
{
    int year;
    float F_M_T;//小甲鱼的实时资金
    for(year = 0,F_M_T = F_M;F_M_T >= 0;year++)
    {
        F_M_T -= F_COST;
        F_M_T *= (1+interst);

    }

    printf("%d年之后,小甲鱼败光了所有的家产,再次回到一贫如洗......\n",year);

    return 0;
}
2.
#include <stdio.h> //计算π的小数点后前7位
#include <math.h>

int main()
{
    double i,j,k;//分母,循环跳出条件,分数
    double result,temp;//结果与临时结果
    _Bool flag = 1;//为1是分数为正,为0是分数为负

    j = pow(10,-8);

    for(temp = 0,i = 1;(1 / i) >= j;i+=2)
    {
        if(flag)
        {
            k = 1 / i;
            flag = 0;
        }
        else
        {
            k = -(1 / i);
            flag = 1;
        }
        temp += k;
    }

    result = 4 *temp;

    printf("结果是:%.7f",result);

    return 0;
}
3.
#include <stdio.h>
#define AIM_Y 2//目标年限

int main()
{
    int total_M,i;//总月份,计数器(月)
    int C_B,C_1_B,C_2_B;//分别表示能繁殖,差一个月能繁殖,差两个月繁殖繁殖
    int temp1 = 0;//差一月能繁殖兔子数量临时存储
    int temp2 = 0;//差两月能繁殖兔子数量临时存储
    total_M = AIM_Y * 12;
    //total_M = 4;//测试基础月份繁殖数量是否正确

    C_B = 1;
    C_1_B = C_2_B = 0;//最初三种繁殖状态的兔子初始数量(对)

    /*每一个月过去就会诞生一批和能繁殖数量一样的差两个月能繁殖的兔子
    就会有差一个月能繁殖数量的兔子变为能繁殖
    差两个月能繁殖的兔子变为差一个月能繁殖
    能繁殖的兔子总是在变多,而差一、两个月能繁殖的兔子会动态变化,由于每个月繁殖会导致差两个月能繁殖的兔子全部成为差一个月繁殖
    故差两个月能繁殖的兔子总是等于当月能繁殖的兔子的数量,差一个月能繁殖的兔子数量同理
    */

    for(i = 1;i<= total_M ;i++)
    {

        temp2 = C_2_B;/*  先取得差两个月能繁殖的兔子数量存储起来,否则被能繁殖的兔子数量覆盖以后,
        就无法得出差一个月能繁殖兔子数量的值,因为差一个月能繁殖的兔子数量与差两个月能繁殖的数量上是相等的,下面同理*/
        C_2_B = C_B;

        temp1 = C_1_B;
        C_1_B = temp2;

        C_B = C_B +temp1;
    }

    printf("经过了%d年,繁殖了%d对兔子\n",AIM_Y,C_B+C_1_B+C_2_B);

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

使用道具 举报

发表于 2020-8-31 21:34:30 | 显示全部楼层
90
9
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-9-1 00:18:35 | 显示全部楼层
对答案
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-20 07:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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