Home >Backend Development >C++ >C program to calculate body mass index (BMI)

C program to calculate body mass index (BMI)

WBOY
WBOYforward
2023-09-03 21:29:063079browse

C program to calculate body mass index (BMI)

Given a person's weight and height, the task is to find his BMI or body mass index and display it.

Calculating body mass index requires two things:

  • Weight
  • Height

You can use the following formula to calculate BMI:

BMI = (mass or weight) / (height*height)

Where the weight is in kilograms and the height is in meters

Example

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

The method used below is as follows

  • Enter weight (kg) and height (meters) in floating point variables
  • Apply the formula to calculate body mass index
  • Print out BMI

Algorithm

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

Example demonstration

#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;
}

Output

If we run The above code will generate the following output

BMI index is : 23.53

The above is the detailed content of C program to calculate body mass index (BMI). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete