Given with the weight and height of a person and the task is to find the BMI i.e. body mass index of his body and display it.
For calculating the body mass index we require two things −
- Weight
- Height
BMI can be calculated using the formula given below −
BMI = (mass or weight) / (height*height)
Where weight is in kg and 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
Approach used below is as follows −
- Input weight(kg) and height(meter) in float variables
- Apply the formula to compute the body mass index
- Print the 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
#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 IT WILL GENERATE FOLLOWING OUTPUT
BMI index is : 23.53