10402
题目
[0.1] 在日常生活中,有很多常用的公式。编写 C 语言程序,实现下列公式。如果不熟悉 scanf()
函数,把数据写在代码里面即可。
- 编写 C 语言程序,实现摄氏度到华氏度的转换。提示:注意数据类型。
- 编写 C 语言程序,计算人的 BMI。
解析
- 摄氏度转华氏度:乘以五分之九再加 32
- BMI:身高除以体重的平方。
答案
(1)
c
#include <stdio.h>
int main() {
float celsius = 25.0;
float fahrenheit;
fahrenheit = (celsius * 9.0 / 5.0) + 32;
printf("摄氏度: %f\n", celsius);
printf("华氏度: %f\n", fahrenheit);
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
(2)
c
#include <stdio.h>
int main() {
float height_in_meters = 1.75;
float weight_in_kg = 68.0;
float body_mass_index;
body_mass_index = weight_in_kg / (height_in_meters * height_in_meters);
printf("身高 (米): %f\n", height_in_meters);
printf("体重 (公斤): %f\n", weight_in_kg);
printf("BMI: %f\n", body_mass_index);
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15