|
发表于 2020-3-7 22:05:17
|
显示全部楼层
0:10
1:运行前感觉是10次,运行后是0次,因为i++执行时i=0,不进入while循环
2:a、b、c
3:a=15 b=5 c=10
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);
count++;
}
while(!(score<0));
printf("count = %d\n",count);
--------------------------
动动手:
0:
#include<stdio.h>
int main()
{
int i=0;
float FishC=10000;
float night=10000;
while(night<=FishC)
{
FishC+=10000*0.1;
night+=night*0.05;
i++;
}
printf("%d年后,黑夜的投资额超过小甲鱼!\n",i);
printf("小甲鱼的投资额是%.2f\n",FishC);
printf("黑夜的投资额是%.2f\n",night);
return 0;
}
1:
#include<stdio.h>
int main()
{
float total=400;
int i=1;
while((total-=50)>0)
{
total+=total*0.08;
i++;
}
printf("%d年之后,小甲鱼败光了了所有的家产,再次回到一贫如洗......\n",i);
return 0;
}
2:
判断条件降了一阶,运行时间太长了,这是1e-7的结果:3.1415966
#include<stdio.h>
#include<math.h>
int main()
{
// float numerator=1;//分子
float approximate_PI=0;//近似值
int i=0;
float denominator=1;//分母
float limit=pow(10,-7);
float fraction;//分数
while((fraction=1/denominator)>=limit)
{
approximate_PI+=pow(-1,i++)*fraction;
denominator+=2;
printf("%.9f %d\n",fraction,i);
}
printf("PI的近似值为:%.7f\n",4*approximate_PI);
return 0;
}
3:
//the answer is 75025
#include<stdio.h>
int main()
{
int year0=1,year1=0,year2=0;
for(int i=1;i<=24;i++)
{
year2+=year1;
year1=year0;
year0=year2;
}
printf("两年之后可以繁殖%d对兔子。\n",year0+year1+year2);
return 0;
}
|
|