项目实践:体重评测器
原理
身体质量指数BMI(Body Mass Index)是一个量度人是否肥胖参考值。是世界公认的一种评定肥胖程度的分级方法。
BMI计算公式
BMI判断标准(成人的BMI)
No. | 级别 | BMI值 |
---|---|---|
1 | 过轻 | 18.5< |
2 | 正常 | 18.5~23.9 |
3 | 超重 | 24~27 |
4 | 肥胖 | 28~32 |
5 | 肥胖 | >32 |
功能
- 分别提示输入体重和身高
- 计算BMI
- 根据BMI输出体重级别
- 如果不在正常范围内输出需要增肥/减肥的最小值。
#include <stdio.h>
#include<math.h>
void Body_Mass_Index(float m, float h){
float BMI;
h=h/100;
BMI=m/(h*h);
printf("BMI:%f\n",BMI);
if(BMI<18.5)
printf("过轻\n");
if(BMI>=18.5&&BMI<=23.9)
printf("正常\n");
if(BMI>=24&&BMI<=27)
printf("超重\n");
if(BMI>=28&&BMI<=32)
printf("肥胖\n");
if(BMI>32)
printf("非常肥胖\n");
}
void suggestion(float m,float h){
float BMI;
float M;
h=h/100;
BMI=m/(h*h);
//printf("%f\n",BMI);
if(BMI<18.5){
BMI=18.5;
M=BMI*h*h;
printf("您需要增肥%.2f(kg)\n",M-m);
}
if(BMI>23.9){
BMI=23.9;
M=BMI*h*h;
printf("您需要减肥%.2f(kg)\n",m-M);
}
}
int main(void) {
float m,h;
printf("请输入体重(kg)和身高(cm):\n");
scanf("%f%f",&m,&h);
Body_Mass_Index(m,h);
suggestion(m,h);
return 0;
}