|
发表于 2025-5-19 13:36:06
|
显示全部楼层
S1E16拾遗
测试题
0.100次
1.0次因为i++先返回0直接退出循环
2.abc都是
3.14,5,9
4.z = x < 0 ? abs(x) : x
5.
A.
if (size > 12)
{
cost = cost * 1.05;
flag = 2;
bill = cost * flag;
}
bill = cost * flag;
B.
if (ibex > 14)
{
sheds = 3;
help = 2 * sheds;
}
help = 2 * sheds;
C.
do
{
scanf("%d", &score);
if (score < 0)
{
break;
}
count++;
}while(True);
printf("count = %d\n", count);
S1E16动动手
0.
#include <stdio.h>
#include <math.h>
int main(){
float money_jiayu = 0;
float money_heiye = 0;
int year = 1;
while (money_jiayu >= money_heiye)
{
money_jiayu = 10000;
money_jiayu = money_jiayu * (1 + 0.1 * year);
money_heiye = 10000;
money_heiye = money_heiye * pow(1.05, year);
year ++;
}
printf("%d年后,黑夜的投资额超过小甲鱼!\n",year - 1);
printf("小甲鱼的投资额是:%.2f\n",money_jiayu);
printf("黑夜的投资额是:%.2f\n",money_heiye);
return 0;
}
S1E16动动手:
1.
#include <stdio.h>
#include <math.h>
int main(){
float cunkuan = 4000000;
int year = 0;
do
{
cunkuan = cunkuan * (1 + 0.08);
year ++;
cunkuan -= 500000;
} while (cunkuan > 0 );
printf("%d年后败光!",year);
return 0;
}
2.
#include <stdio.h>
#include <math.h>
int main()
{
double fenmu = 1;
double a = pow(10,-8);
double latest = fabs(a);
double count = 0;
int j = 1;
double result;
while (1 / fenmu >= latest)
{
count = count + j * (1 / fenmu);
j = -j;
fenmu = fenmu + 2;
}
result = count * 4;
printf("π的值是:%.7f\n",result);
printf("Hello");
return 0;
}
S1E16动动手:
3.不会。我感觉这需要面向对象的编程处理起来会比较简单。 |
|