Calculate the Body Mass Index (BMI) from a person's height and weight, then determine which category they fall into.

BMI Formula: BMI = weight (kg) / (height (m))²

Categories:

  • Underweight: BMI < 18.5
  • Normal weight: BMI 18.5 - 24.9
  • Overweight: BMI 25.0 - 29.9
  • Obese: BMI ≥ 30.0

Return the BMI value rounded to 1 decimal place and the corresponding category as a string.

Input & Output

Example 1 — Normal Weight
$ Input: weight = 70, height = 1.75
Output: 22.9 Normal weight
💡 Note: BMI = 70 / (1.75)² = 70 / 3.0625 = 22.857... rounds to 22.9. Since 18.5 ≤ 22.9 < 25.0, category is Normal weight.
Example 2 — Overweight
$ Input: weight = 85, height = 1.70
Output: 29.4 Overweight
💡 Note: BMI = 85 / (1.70)² = 85 / 2.89 = 29.411... rounds to 29.4. Since 25.0 ≤ 29.4 < 30.0, category is Overweight.
Example 3 — Underweight
$ Input: weight = 45, height = 1.65
Output: 16.5 Underweight
💡 Note: BMI = 45 / (1.65)² = 45 / 2.7225 = 16.528... rounds to 16.5. Since 16.5 < 18.5, category is Underweight.

Constraints

  • 1 ≤ weight ≤ 1000
  • 0.1 ≤ height ≤ 3.0
  • BMI will be rounded to 1 decimal place

Visualization

Tap to expand
BMI Calculator OverviewINPUTWeight70 kgHeight1.75 mPerson's physical measurementsfor health assessmentALGORITHM STEPS1Calculate BMIBMI = weight / (height)²2Round to 1 decimal22.857... → 22.93Check thresholds18.5 ≤ 22.9 < 25.04Determine categoryNormal weightFINAL RESULTBMI & Category22.9Normal weightHealth assessment completeKey Insight:The BMI formula combined with ordered threshold checking provides instant health categorization from basic measurements.TutorialsPoint - BMI Calculator | Optimized If-Else Chain
Asked in
Healthcare Systems 25 Fitness Apps 30
33.2K Views
Medium Frequency
~5 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen