S1E16:拾遗 | 课后测试题及答案 [修改
1
做完啦,对个答案案{:10_279:}
冲鸭
本帖最后由 焦糖橙子 于 2021-7-25 19:37 编辑
#include<stdio.h>
#include <math.h>
int Q1()
{
int i, j = 0;
for (i = 0; i != 10, j != 10; i++)
{
for (j = 0; j < 10; j++)
{
putchar('A');
}
}
putchar('\n');
return 0;
}
/*
a 14
b 3 4 5
c 8 9
*/
int Q4()
{
double x, z;
printf("请输入一个数:");
scanf("%lf", &x);
z = x > 0 ? x : (-x);
printf("z的值为:%f\n", z);
return 0;
}
int QQ0()
{
float interst = 0.1, interst_d = 0.05;
float a = 10000, b = 10000, sum_a = a, sum_b = b;
int year = 1;
do
{
sum_a = sum_a +a *interst * year;
sum_b = sum_b * (1 +interst_d);
year++;
} while (sum_a > sum_b);
printf("%d年后,黑夜的投资额超过小甲鱼!\n",year);
printf("小甲鱼的投资额是:%.2f\n", sum_a);
printf("黑夜的投资额是:%.2f\n", sum_b);
return 0;
}
int QQ1()//天降横财
{
float a = 4000000;
int year = 0;
do
{
a = a + a * 0.08;
a = a - 500000;
year++;
} while (a > 0);
printf("%d年之后,小甲鱼败光了所有的家产,再次回到一贫如洗......\n", year);
return 0;
}
int QQ2()//计算PI的小数点后前7位
{
double i = 1, j = 1;
double PI = 0;
while (fabs(1 / j > pow(10, -8)))
{
PI = PI + (i / j);
i = -i;
j = j + 2;
}
PI = PI * 4;
printf("PI的值约为%.7f\n", PI);
return 0;
}
int QQ3()//兔子繁殖问题
{
int i, j ;
double k = 0;
i = 2;
for (j = 0; j <= 12; j++)
{
k = pow(i, j);
}
printf("两年之后可以繁殖%.0f对兔子。\n", k);
return 0;
}
兔子那题没看懂,我去查查资料。
dge
1
1
查看参考答案
加油
66
0.100个
1.11个
2.ab c
3.a = 3 b = 5 c = 9
4.z = x >= 0 ? x : -x
5.
A.
if (size > 12)
{
cost *= 1.05;
flag = 2;
}
bill = cost * flag
B.
if (ibex > 14)
{
sheds = 3;
}
sheds = 2;
help = 2 * sheds;
C.
{:5_90:}
l
0
0.#include <stdio.h>
#define MONEY 10000
int main()
{
double a_total = MONEY, b_total = MONEY;
int count = 0;
do
{
a_total += MONEY * 0.1;
b_total += b_total * 0.05;
count++;
} while(a_total >= b_total);
printf("%d年后,黑夜的投资额超过小甲鱼!\n", count);
printf("小甲鱼的投资额是:%.2f\n", a_total);
printf("黑夜的投资额是:%.2f\n", b_total);
return 0;
}
1.
#include <stdio.h>
int main()
{
double awards = 4000000;
int count = 0;
while (awards >= 0)
{
awards -= 500000;
awards += awards * 0.08;
count++;
}
printf("%d年之后,小甲鱼败光了所有的家产,再次回到一贫如洗……\n", count);
return 0;
}
2.#include<stdio.h>
int main(){
int term,denominator;//项数 ,分母
float sign=1.0;//分子
float pi = 0.0;
for(term=0;term<700000;term++){
denominator=2*term+1;//这里面表示奇数项
pi = pi+(sign/denominator);
sign = -sign;
}
pi = pi*4.0;
printf("pi的近似值为%10.7f",pi);
}
3.
1
0.100
1.11
2.
3.a=14;b=5;c=9
4.
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);
3
感谢