用于计算体重指数(BMI)的C程序

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

要计算身体质量指数,我们需要两个条件

  • 重量(Weight)

  • 高度(Height)

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-> 声明计算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>
//计算BMI指数的功能
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