
给定一个人的体重和身高,任务是找到他的BMI即身体质量指数,并显示出来。
计算身体质量指数需要两个东西:
体重身高
可以使用下面的公式计算BMI:
BMI = (质量或体重) / (身高*身高)
其中体重以千克为单位,身高以米为单位
示例
Input 1-: weight = 60.00 Height = 5.1Output -: BMI index is : 23.53Input 2-: weight = 54.00 Height = 5.4Output -: BMI index is : 9.3
下面使用的方法如下 −
在浮点变量中输入体重(kg)和身高(米)应用公式计算身体质量指数打印出BMI
算法
StartStep 1-> Declare function to calculate BMI float BMI(float weight, float height) return weight/height*2step 2-> In main() Set float weight=60.00 Set float height=5.1 Set float bmi = BMI(weight,height) Print BMIStop
Example
实例演示
#include//function to calculate BMI indexfloat 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)的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1444324.html
微信扫一扫
支付宝扫一扫