Pueblo 发表于 2026-3-7 00:14:59

1

vw_50 发表于 2026-3-10 13:24:56

{:9_218:}

半凡客 发表于 2026-3-12 15:30:49

{:5_101:}

yzxkk 发表于 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.

zbbbw 发表于 2026-3-19 14:34:12

1

BoluoK1NG 发表于 2026-3-23 15:07:35

1

the_yu_ 发表于 2026-3-28 16:48:02

4

mornings 发表于 2026-3-28 16:57:14

查看参考答案

jxgyhp 发表于 2026-3-30 20:45:17

jj'

HovQ 发表于 2026-4-1 23:15:45

10个
10个
c b a
15 4 10
z =abs(x)
if (size > 12)
{
      cost *=1.05

七元龙井茶 发表于 2026-4-3 09:34:29

汪立伟 发表于 2026-4-4 20:56:49

看看

睡觉One 发表于 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;
}

跳进海里多余 发表于 2026-4-10 09:02:34

勿失信 发表于 2026-4-12 11:41:58

1

czzmvp 发表于 2026-4-13 20:08:37

1

是蓝蓝吖 发表于 2026-4-15 02:44:03

0. 请问下边代码将打印多少个 'A'
i (0~9)    j (0~9)
100次(外层10次 * 内层10次)



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


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



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

(c+1) + (b+1)
a = 14 (9+5)




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




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

【1】
if (size > 12)
{
        cost = cost * 1.05;
        flag = 2;
}
bill = cost * flag;



【2】
if (ibex > 14)
{
        sheds = 3;
        help = 2 * sheds;
}
sheds = 2;
help = 2 * sheds;



【3】
do
{
        scanf("%d", &score);
        count++;
}
while(score > 0)
printf("count = %d\n", count);

是蓝蓝吖 发表于 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;
}
页: 283 284 285 286 287 288 289 290 291 292 [293] 294
查看完整版本: S1E16:拾遗 | 课后测试题及答案