|
发表于 2023-12-9 12:29:57
|
显示全部楼层
测试题
0:100个A
1:1个B
2:a
3:a=11,b=3,c=8
4:if(x>0)
{
z=x;
}
else
{
z=-x;
}
5:
A:if (size > 12)
{
cost = cost * 1.05;
flag = 2;
}
else
{
bill = cost * flag;
}
B:if (ibex > 14) {
sheds = 3;
} else {
sheds = 2;
}
help = 2 * sheds;
C:readin: scanf("%d", &score);
if (score < 0)
{
printf("count = %d\n", count);
}
else
{
count++;
scanf("%d", &score);
}
动动手
0:
#include <stdio.h>
int main() {
float xiaojiafish = 10000; // 小甲鱼手上的钱
float heiye = 10000; // 黑夜手上的钱
float xiaojiafish_interest, heiye_interest = 0; // 利息
int year = 0;
while (xiaojiafish >= heiye) {
xiaojiafish_interest = xiaojiafish * 0.1; // 计算小甲鱼的单利息
xiaojiafish += xiaojiafish_interest; // 更新小甲鱼的总投资额
heiye_interest = heiye * 0.05; // 计算黑夜的复合利息
heiye += heiye_interest; // 更新黑夜的总投资额
year++; // 年数加一
}
printf("经过 %d 年,黑夜的投资额 %f 超过了小甲鱼的投资额 %f\n", year, heiye, xiaojiafish);
return 0;
}
1:
#include <stdio.h>
int main()
{
float a;
a = 400;
float b;
b = 0;
int year;
while(a >= 0)
{
b = a * 0.08;
a += b;
a = a - 50;
year++;
}
printf("经过 %d 年,小甲鱼败光属于家产,再次回到一贫如洗\n",year);
return 0;
}
2:
#include <stdio.h>
#include <math.h>
int main() {
double pi = 0.0;
double item = 1.0;
int i = 1;
while (fabs(item) >= 1e-8) {
pi += item;
i = -i;
item = 1.0 / (2 * i + 1);
}
pi *= 4;
printf("π 的近似值为: %.7f\n", pi);
return 0;
}
3:
#include <stdio.h>
#include <math.h>
int main() {
double pi = 0.0;
double item = 1.0;
int i = 1;
while (fabs(item) >= 1e-8) {
pi += item;
i = -i;
item = 1.0 / (2 * i + 1);
}
pi *= 4;
printf("π 的近似值为: %.7f\n", pi);
return 0;
}
|
|