|
发表于 2016-12-22 23:37:45
|
显示全部楼层
测试题
0. 10
1. 10
2. c , b ,a
3. a=14,b=5,c=9
4.
if(x < 0)
{
z = -1 * x;
}else{
z = x;
}
5.
A:
if(size > 12)
{
cost = cost * 1.05;
}else{
bill = cost * flag;
}
B:
if(ibex > 14)
{
sheds = 3;
}else{
sheds = 2;
}
help = 2 * sheds;
C:
while(scanf("%d",&score))
{
if(score < 0)
{
printf("count = %d\n",count);
break;
}
count++;
}
动动手
0.
#include <stdio.h>
#include <math.h>
int main()
{
int i = 0;
float moneyX,moneyH;
while(++i)
{
moneyX = 10000 + 10000 * i * 0.1;
moneyH = pow(1 + 0.05,i) * 10000;
if(moneyH > moneyX)
{
break;
}
}
printf("%d年后,黑夜的投资额超过小甲鱼!\n",i);
printf("小甲鱼的投资额是:%.2f\n",moneyX);
printf("黑夜的投资额是:%.2f\n",moneyH);
}
1.
#include <stdio.h>
int main()
{
int i ;
double money = 4000000;
for(i = 1, money -= 500000;money > 0;money -= 500000)
{
money += money * 0.08;
i++;
}
printf("%d年后,小甲鱼败光了所有的家产,再次回到穷光蛋。。。\n",i);
}
2.
#include <stdio.h>
#include <math.h>
int main()
{
double pi = 0,temp;
double num = 10e-8;
int n = 1,i = 0;
while(1)
{
temp = ((double)1 / n) * pow(-1,i);
if (fabs(temp) < num)
{
break;
}
pi += temp;
n += 2;
i++;
}
pi *= 4;
printf("Pi = %.7f\n",pi);
return 0;
}
3.
#include <stdio.h>
int main()
{
int j,temp1,temp2;
int num0 = 1,num1 = 0,num2 = 0; //分别代表刚出生的,出生1月,出生两月可繁殖
for (j = 1;j <=24;j++)
{
temp1 = num0; //存储上个月刚出生的兔子
temp2 = num1; //存储上个月出生1个月的兔子
num0 = num2; //本月刚出生的是上月可以繁殖兔子的数量
num1 = temp1; //出生1个月的是上月刚出生的
num2 = num2 + temp2; //出生两月以上的是之前两月的加上上个月出生1月的
}
printf("两年过后总共有%d对兔子",num0 + num1 +num2);
return 0;
} |
|