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

下面使用的方法如下

  • 以浮点数变量形式输入体重(公斤)和身高(米)
  • 应用公式计算体重指数
  • 打印 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

示例

 在线演示

#include<stdio.h>
//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

更新时间:2019 年 10 月 18 日

10K+ 浏览

启动你的 事业

完成课程获得认证

开始
广告
© . All rights reserved.