|
发表于 2024-5-11 15:27:38
|
显示全部楼层
测试题
0.10个
1.0个
2.c, b, a
3.14,5,9
4. z = (a >= 0) ? a : 0 - a;
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.
while (1)
{
scanf("%d", &score);
if (score < 0)
{
break;
}
count++;
}
printf("count = %d\n", count);
动动手
0.
#include <stdio.h>
int main()
{
double jia, hei;
jia = 10000, hei = 10000;
int year = 0;
while (jia >= hei)
{
jia += 10000 * 0.1;
hei *= 1.05;
year++;
}
printf("%d年后,黑夜的投资额超过小甲鱼!\n",year);
printf("小甲鱼的投资额是:%.2f\n",jia);
printf("黑夜的投资额是:%.2f\n",hei);
return 0;
}
1.
#include <stdio.h>
int main()
{
double money = 400;
int year = 0;
while (money >= 0)
{
money -= 50;
money *= 1.08;
year++;
}
printf("%d年之后,小甲鱼败光了所有的家产,再次回到一贫如洗......",year);
return 0;
}
2.
#include <stdio.h>
#include <math.h>
int main()
{
double pi4 = 0.0;
double pi;
double mu = 1.0;
double cha = 1.0;
double a = -1.0;
const double f = pow(10, -8);
//printf("%.8f\n", f);
while (cha > f)
{
a = -a;
pi4 = pi4 + a / mu;
mu += 2;
pi = pi4 * 4;
cha = fabs(pi - 3.14159265);
//printf("%.8f\n",cha);
}
printf("pi的近似值是:%.9f",pi);
return 0;
}
3.
#include <stdio.h>
int main()
{
int month, da, x0, x1; //月份,大兔子,0个月兔子,1个月兔子
int num = 0;
da = 1;
x0 = 0, x1 = 0;
for (month = 0; month < 24; month++)
{
da += x1; //1兔子长大
x1 = x0; //0兔子长大
x0 = da; //大兔子生0兔子
}
num = da + x1 + x0;
printf("两年之后,兔子数量为:%d",num);
return 0;
}
|
|