测试题:
0、10
1、不打印B;
2、a、b、c
3、
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;
}
sheds = 2;
help = 2 * sheds;
C:if (score < 0)
{
printf("count = %d\n", count);
}
count++;
scanf("%d", &score);
动动手:
0、
 #include <stdio.h>
#include <math.h>
int main()
{
int money_ini= 10000;
int money1, money2;
money1= 0;
money2 = money_ini;
float rate1 = 0.1, rate2 = 0.05;
int year;
for (year =1; year < 100; year++) {
money1 = money_ini *rate1*year+ money_ini;
money2 = money2 * (1+rate2);
if (money2 > money1) {
printf("经过%d年后,超过!", year);
printf("小甲鱼的投资额为:%d", money1);
printf("黑夜的投资额为:%d", money2);
break;
}
}
return 0;
}
1、#include <stdio.h>
int main() {
float rate = 0.08;
float total_money = 400;
float cost = 50;
int year = 0;
for (year; year < 100; year++) {
total_money = (total_money - cost)*(1 + rate);
if (total_money < cost) {
printf("%d年之后,小甲鱼一贫如洗!",year+1);
break;
}
}
return 0;
}
2、#include <stdio.h>
#include <math.h>
int main() {
double result=0,temp;
int i = 1;
for (; i < 10000000000; i++) {
if (i % 2 == 0)//求余,偶数
{
temp = -1 / double((2 * i - 1));
}
else {
temp = 1 / double((2 * i - 1));
}
if (fabs(temp) < 1e-8) {
break;
}
result = result + temp;
}
printf("pi=%.7f\n",4*result);
//printf("i=%d\n",i);
//printf("%.10f\n",1e-8);
return 0;
}
|