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:
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
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 −
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 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; }
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!