初学者00000001 发表于 2022-2-24 23:36:58

yfccc 发表于 2022-2-25 00:03:31

本帖最后由 yfccc 于 2022-2-25 13:03 编辑

0. 8110次,因为逗号表达式只执行后面的
1. 0
2. c,b,a
3. b=5 c=9 a=14
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.
if (score < 0)
{
      printf("count = %d\n", count);
}
count++;
scanf("%d", &score);

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


0.
#include<stdio.h>
#include<math.h>
int func1();
int func2();
int func3();
int func4();

int main()
{
        func1();
      func2();
        func3();
        func4();


        return 0;
}

int func1()
{
        float pir = 10000;
        float total_1,total_2;
        int year=1,b = 1;
        while(b)
        {
                total_1 = pir + pir*0.1*year;
                total_2 = pir * pow(1.05,year);
                if(total_1 < total_2)
                {
                        b=0;
                        printf("%d年后,黑夜的投资额超过小甲鱼!\n小甲鱼的投资额是: %.2f\n黑夜的投资额是: %.2f\n",year,total_1,total_2);
                }
                year++;
        }
        return 0;
}

int func2()
{
        float money = 400;
        float interest = 0.08;
        int year = 1;
        int b = 1;
        while(b)
        {
                money = (money-50)*(1+interest);
                if(money<0)
                {
                        b=0;
                        printf("%d年之后,小甲鱼败光了所有的家产,再次回到一贫如洗……\n",year);
                }
                year+=1;
        }
        return 0;
}

int func3()
{
        double i = 1;
        double pi4 = 0;

        while((1/i)>pow(10,-8))
        {
                pi4 = pi4 + 1/i-1/(i+2);
                i = i+4;
        }
        if((1/(i-2))<pow(10,-8))
        {
                pi4 = pi4 + 1/(i-2);
        }
        printf("%.7f",pi4*4);

        return 0;
}

int func4()
{
        int rabbit_1 = 1,rabbit_2 = 1,rabbit;
        for(int month = 1; month<=2*12; month++)
        {
                rabbit = rabbit_1 + rabbit_2;
                rabbit_1 = rabbit_2;
                rabbit_2 = rabbit;
        }
        printf("两年后,总共有%d只兔子!\n", rabbit);
        return 0;
}

zxy22 发表于 2022-2-25 11:13:29

z

么11 发表于 2022-2-25 12:43:26

a

吃不大的瘦子 发表于 2022-2-26 15:13:54

,

机械人 发表于 2022-2-26 18:27:42

+1

写个bug 发表于 2022-2-26 19:02:53

kk

lolin.201903 发表于 2022-2-26 20:34:45

1

泽大大 发表于 2022-2-26 21:33:03

0 1009次
1 11次
2 a,b,c
3 a=14 b=3,c=9
4 z=(x>0?x:-x);

zerock5205 发表于 2022-2-27 12:37:18

{:10_261:}

随宇 发表于 2022-2-27 14:38:26

{:5_101:}

胡渣哥 发表于 2022-2-27 16:01:07

#include <stdio.h>
int main()
{
        int a,yir,i = 4000000;
        i= i + i*8/100;
       
        for(yir = 2;i/500000;yir++)
          {
                       i= i + i*0.08;
                           i=i-500000;
          }
          printf("需要%d年i=%d",yir,i);
          return 0 ;
       
}

#include <stdio.h>
int main()
{
        int i,a=0,b=1,c=0;
       
    for(i = 1;i <24;i++)
       {
                 c = a + b;
                 a = b;
                 b = c;
                 
           }
           printf("一共有%d",c);
          
           return 0;
}

godwu 发表于 2022-2-27 17:10:02

#include<stdio.h>
#include<math.h>
int main()
{
        double pi=0,i=1;
        int num=1;
       
        do
        {
               
                pi=pi+4*1/i;
                num++;
               
                if(num%2==0)
                {
                        i=-i;
                        i=i-2;
                }
                else
                {
                        i=-i;
                        i=i+2;
                }
        }while(fabs(1/i)>pow(10,-8));
       
       
        printf("%.7lf",pi);
        return 0;
}
#include<stdio.h>

int main()
{
        float money =4000000.00,r=0.08;
        int year=0;
        do
        {
                money=money-500000;
                money=money*(1+r);
               
                year++;
       
        }while(money>0);
       
        printf("%d",year);
        return 0;
}
#include<stdio.h>

int main()
{
        float a,r1=0.10,r2=0.05,x=10000.00,y=10000.00;
        int b=0;
        do
        {
        a=10000*r1;
        x=a+x;
        y=y*(1+r2);
        b++;       
        }while(x>y);
        printf("%d %.2f %.2f\n",b,x,y);
        return 0;
}

windark 发表于 2022-2-27 18:19:51

大佬牛逼

1664645836 发表于 2022-2-27 22:52:02

答案

WuBrandon 发表于 2022-2-28 09:35:51

1

BEAR-M 发表于 2022-2-28 15:54:06

10
9

风渐渐 发表于 2022-2-28 17:10:16

0.10
1.10
2.c
3.a=14,b=3,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);

253443169 发表于 2022-2-28 20:23:00

1

新手入场 发表于 2022-2-28 20:41:20

4
页: 206 207 208 209 210 211 212 213 214 215 [216] 217 218 219 220 221 222 223 224 225
查看完整版本: S1E16:拾遗 | 课后测试题及答案