Home > Backend Development > C++ > body text

C program to calculate body mass index (BMI)

WBOY
Release: 2023-09-03 21:29:06
forward
3028 people have browsed it

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
Copy after login

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
Copy after login

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;
}
Copy after login

Output

If we run The above code will generate the following output

BMI index is : 23.53
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template