|
发表于 2022-3-29 15:43:15
|
显示全部楼层
本帖最后由 ZHONG.Y.H 于 2022-3-29 15:47 编辑
测试题
0:10次
1:0次
2:c, b, a
3:首先 b = 3(因为赋值运算符的优先级比逗号运算符高);c = b++ + 5,c = 8(因为 b++ 是先使用变量 b 的值,再将自身加一);a 最后的值是 ++c + ++b,此时 c = 8,b = 4,则 a = 9 + 5,最后 a = 14, b = 5, 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);
动动手:
0:
#include "stdio.h"
int main()
{
double fish = 10000;
double night = 10000;
int i = 1;
do
{
fish = fish + 10000 * 0.1;
night = night * (1 + 0.05);
i++;
}while(fish > night);
printf("%d\n", i);
return 0;
}
1:
#include "stdio.h"
int main()
{
double money = 4000000;
int i = 1;
while(money > 0)
{
money = money * (1 + 0.08);
money = money - 500000;
i++;
}
printf("%d", i);
return 0;
}
2:
#include <stdio.h>
#include <math.h>
int main()
{
int sign = 1; // 表示符号
double pi = 0.0, n = 1, term = 1.0; // n表示分母,term表示当前项的值
while (fabs(term) >= 1e-8) // 1e-8表示10^(-8)
{
pi = pi + term;
n = n + 2;
sign = -sign;
term = sign / n;
}
pi = pi * 4;
printf("pi = %10.7f\n", pi);
return 0;
}
3:#include <stdio.h>
int main()
{
long a = 1, b = 1, c, i;
for (i = 3; i <= 24; i++)
{
c = a + b;
a = b;
b = c;
}
printf("两年后,总共有%ld只兔子!\n", c);
return 0;
}
|
|