문제
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')
'-- 예전 기록 > BOJ' 카테고리의 다른 글
[ BOJ ] 5719 : 거의 최단 경로 ( PLATINUM 5 ) / Python (0) | 2023.10.03 |
---|---|
[ BOJ ] 2908 : 상수 ( BRONZE 2 ) / C, C++, Python, Java (0) | 2023.10.03 |
[ BOJ ] 19602 : Dog Treats ( BRONZE 4 ) / C, Python (0) | 2023.10.03 |
[ BOJ ] 28701 : 세제곱의 합 ( BRONZE 5 ) / C, Python (0) | 2023.10.03 |
[ BOJ ] 5585 : 거스름돈 ( BRONZE 2 ) / C, Python (0) | 2023.10.03 |