C程序计算身体质量指数(BMI)

2023年 9月 3日 16.2k 0

C程序计算身体质量指数(BMI)

给定一个人的体重和身高,任务是找到他的BMI即身体质量指数,并显示出来。

计算身体质量指数需要两个东西:

  • 体重
  • 身高

可以使用下面的公式计算BMI:

BMI = (质量或体重) / (身高*身高)

其中体重以千克为单位,身高以米为单位

示例

Input 1-: weight = 60.00
Height = 5.1
Output -: BMI index is : 23.53
Input 2-: weight = 54.00
Height = 5.4
Output -: BMI index is : 9.3

登录后复制

下面使用的方法如下 −

  • 在浮点变量中输入体重(kg)和身高(米)
  • 应用公式计算身体质量指数
  • 打印出BMI

算法

Start
Step 1-> Declare function to calculate BMI
float BMI(float weight, float height)
return weight/height*2
step 2-> In main()
Set float weight=60.00
Set float height=5.1
Set float bmi = BMI(weight,height)
Print BMI
Stop

登录后复制

Example

实例演示

#include
//function to calculate BMI index
float BMI(float weight, float height) {
return weight/height*2;
}
int main() {
float weight=60.00;
float height=5.1;
float bmi = BMI(weight,height);
printf("BMI index is : %.2f ",bmi);
return 0;
}

登录后复制

输出

如果我们运行上述代码,将会生成以下输出

BMI index is : 23.53

登录后复制

以上就是C程序计算身体质量指数(BMI)的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论