是蓝蓝吖 发表于 2026-4-15 04:04:47

//利息计算
//启动资金10000
//固定利息 = 本金*0.1%
//复合利息 = (本金+产生的利息)*0.05%
#include<stdio.h>
int main()
{
        float a = 10000;
        float b = 10000;
        int count = 0;
        float ra = a * 0.1;

        do
        {
                a += ra;                        //固定利息
                b += (b * 0.05);        //复利
                count++;
        } while (b < a);

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





//本金400万   每年0.08利息   每年开支50万   算几年后破产
#include<stdio.h>
int main()
{
        float a = 4000000;
        int count = 0;
        while (a > 0)
        {
                a -= 500000;        //开销
                a += a * 0.08;        //利息
                count++;
        }

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






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

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

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








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

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

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

                //换行 格式
                if (count % 6 == 0)
                        printf("\n");
        }
        return 0;
}

lsr3355 发表于 2026-4-15 09:29:25

{:10_277:}

AkikoEra 发表于 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:
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:
scanf("%d", &score);
while(score < 0)
{
count ++
scanf("%d", &score);
}
printf("count = %d\n", count);

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

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

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

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

return EXIT_SUCCESS;
}


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

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

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

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

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

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

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

return EXIT_SUCCESS;
}


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

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

int month = 3;

int firstmonth, sencondmonth;
firstmonth = 1;
sencondmonth = 1;
while (month <= 24) {

    a = firstmonth + sencondmonth;
    sencondmonth = firstmonth;
    firstmonth = a;

    month++;
}

printf("%ld\n", a);
return EXIT_SUCCESS;
}

MakiCHN 发表于 2026-4-16 18:41:33

10个A

Jazzhaitao251 发表于 2026-5-9 22:13:57

尽力了

小正阿 发表于 2026-6-4 20:54:24

本帖最后由 小正阿 于 2026-6-4 21:01 编辑

0. 10 个。

1. 0个。

2. 不清楚。

3.
a = 14
b = 5
c = 9

液幽hug 发表于 2026-6-11 14:18:44

111

小田田 发表于 2026-6-14 12:26:04

111

Pic_ss0 发表于 2026-6-18 10:51:36

+1

磊之茶 发表于 2026-6-23 07:46:48


融火焚身 发表于 2026-6-25 11:14:37

.

剑来龙族悍刀行 发表于 3 天前

.
页: 284 285 286 287 288 289 290 291 292 293 [294]
查看完整版本: S1E16:拾遗 | 课后测试题及答案