-- 예전 기록/BOJ

[ BOJ ] 6825 : Body Mass Index ( BRONZE 4 ) / C, Python

rejo 2023. 10. 3. 10:50

문제

The Body Mass Index (BMI) is one of the calculations used by doctors to assess an adult’s health. The doctor measures the patient’s height (in metres) and weight (in kilograms), then calculates the BMI using the formula

BMI = weight/(height × height).

Write a program which prompts for the patient’s height and weight, calculates the BMI, and displays the corresponding message from the table below.


More than 25 Overweight
Between 18.5 and 25.0 (inclusive) Normal weight
Less than 18.5 Underweight

풀이 과정

몸무게가 kg 단위로, 키가 m 단위로 주어진다. 이를 이용해 BMI 를 계산하여 조건에 맞는 BMI 메시지를 표시하자.

C

#include <stdio.h>

int main(void) {
    double weight, height;
    scanf("%lf", &weight);
    scanf("%lf", &height);

    double bmi = weight / (height * height);
    if (bmi > 25) printf("Overweight");
    else if (bmi < 18.5) printf("Underweight");
    else printf("Normal weight");
    
    return 0;
}

Python

w = float(input().rstrip())
h = float(input().rstrip())
r = w/(h*h)

if r > 25: print('Overweight')
elif 18.5 <= r <= 25: print('Normal weight')
else: print('Underweight')