알고리즘 28 - Calculate BMI

tamagoyakii·2021년 10월 9일
0

알고리즘

목록 보기
28/89

Q.

Write function bmi that calculates body mass index (bmi = weight / height2).

if bmi <= 18.5 return "Underweight"

if bmi <= 25.0 return "Normal"

if bmi <= 30.0 return "Overweight"

if bmi > 30 return "Obese"

A)

const char *bmi (int weight, double height) {
  double bmi = weight / (height * height);
  if (bmi <= 18.5)
    return "Underweight";
  else if (bmi <= 25.0)
    return "Normal";
  else if (bmi <= 30.0)
    return "Overweight";
  else
    return "Obese";
}

0개의 댓글