Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
C program to Calculate Body Mass Index (BMI)
Body Mass Index (BMI) is a health metric used to assess whether a person has a healthy body weight relative to their height. In C programming, we can calculate BMI using a simple formula.
Syntax
BMI = weight / (height * height)
Where weight is in kilograms and height is in meters.
Example: BMI Calculator
This example demonstrates how to calculate BMI using a function −
#include <stdio.h>
// Function to calculate BMI
float calculateBMI(float weight, float height) {
return weight / (height * height);
}
int main() {
float weight = 60.0; // weight in kg
float height = 1.7; // height in meters
float bmi;
bmi = calculateBMI(weight, height);
printf("Weight: %.1f kg
", weight);
printf("Height: %.1f m
", height);
printf("BMI: %.2f
", bmi);
// BMI categories
if (bmi < 18.5) {
printf("Category: Underweight
");
} else if (bmi < 25.0) {
printf("Category: Normal weight
");
} else if (bmi < 30.0) {
printf("Category: Overweight
");
} else {
printf("Category: Obese
");
}
return 0;
}
Weight: 60.0 kg Height: 1.7 m BMI: 20.76 Category: Normal weight
Example: Interactive BMI Calculator
This example takes user input for weight and height −
#include <stdio.h>
float calculateBMI(float weight, float height) {
return weight / (height * height);
}
int main() {
float weight, height, bmi;
printf("Enter weight in kg: ");
scanf("%f", &weight);
printf("Enter height in meters: ");
scanf("%f", &height);
bmi = calculateBMI(weight, height);
printf("\nYour BMI is: %.2f
", bmi);
return 0;
}
BMI Categories
| BMI Range | Category |
|---|---|
| Below 18.5 | Underweight |
| 18.5 - 24.9 | Normal weight |
| 25.0 - 29.9 | Overweight |
| 30.0 and above | Obese |
Key Points
- BMI is calculated as weight (kg) / height² (m²)
- Height must be in meters for accurate calculation
- BMI provides a general health indicator but doesn't account for muscle mass
- Always validate input to ensure positive values for weight and height
Conclusion
Calculating BMI in C is straightforward using the standard formula. The program can be enhanced to include BMI categories and input validation for better user experience.
Advertisements
