|
发表于 2020-3-11 15:57:08
|
显示全部楼层
0题.10次
1题.9次
2题:5是c的l-value,c是b的l-vallue,以此类推。
3题:a = 14; b = 5; c = 9;
4题:
#include <stdio.h>
int main()
{
float x, z;
printf("请输入一个数字:\n");
scanf("%f", &x);
if (x > 0)
z = x;
else
z = -x;
printf("绝对值为:%.2f\n", z);
return 0;
}
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:
while (1)
{
scanf("%d", &score);
if (score < 0);
{
printf("cout = %d\n", count);
break;
}
count++;
}
动动手:
0题:
#include <stdio.h>
int main()
{
int year = 0;
double lwg = 10000, hy = 10000, wp, hp;
hp = hy;
wp = lwg;
while (hp <= wp)
{
wp = wp + lwg * 0.1;
hp = hp + hp * 0.05;
year++;
}
printf("%d年后,黑夜的投资额超过小甲鱼\n", year);
printf("小甲鱼的投资额为:%.2f\n", wp);
printf("黑夜的投资额为:%.2f\n", hp);
return 0;
}
1题:
#include<stdio.h>
int main()
{
double lotty = 4000000, div;
int year = 1;
div = 4000000 * 0.08;
do
{
lotty = lotty + div - 500000;
div = lotty * 0.05;
year++;
} while (lotty >= 0);
printf("%d年后,小甲鱼败光了所有的家产,再次回到一贫如洗......", year);
return 0;
}
2题:
#include<stdio.h>
#include<math.h>
int main()
{
long double tmp, pi = 0, den = 1;
int key = 1;
do
{
tmp = 1 / den;
if (key % 2)
pi = pi + tmp;
else
pi = pi - tmp;
key++;
den = den + 2;
}while (tmp > pow(10, -8));
pi = 4 * pi;
printf("pi的近似值为:%0.7f", pi);
return 0;
}
3题:
#include<stdio.h>
#include<math.h>
int main()
{
//y_0num表示0个月的兔子,y_0t是一个防止计算混乱的中间值。
long int num, y_0num = 2, y_0t = 0, y_1num = 0, y_1t = 0, y_onum = 0, y_ot = 0;
int month = 1;
while (month <= 24)
{
if (y_0num)
{
y_1t = y_0num;
y_0num = 0;
}
if (y_1num)
{
y_ot = y_1num;
y_1num = 0;
}
if (y_onum)
{
y_0t = y_onum * 2;
}
//传导数据
y_0num = y_0t;
y_1num = y_1t;
y_onum = y_onum + y_ot;
//中间值清零
y_0t = 0;
y_1t = 0;
y_ot = 0;
month++;
}
num = y_0num + y_1num + y_onum;
printf("两年后,共有%ld只兔子",num);
return 0;
} |
|