모든 챌린지
쉬움 3명 해결 정답률 100.0%

Body Mass Index

Compute BMI from weight and height.

배우게 될 내용

  • Square a value and divide
  • Work with decimals
  • Translate a formula into code

문제

번역본 보기

Body mass index (BMI) is weight in kilograms divided by the square of height in meters.

Implement body_mass_index(weight_kg, height_m).

Input

weight_kg: Weight in kilograms. height_m: Height in meters.

Output

Return weight_kg / (height_m × height_m).

제약 조건

1 ≤ weight_kg ≤ 500; 0.5 ≤ height_m ≤ 2.5

예시

예시 1
입력:
weight_kg = 72.0
height_m = 1.8

예상 출력:
expected = 22.222222
입력:
double weight_kg = 72.0;
double height_m = 1.8;

예상 출력:
double expected = 22.222222;
입력:
double weight_kg = 72.0;
double height_m = 1.8;

예상 출력:
double expected = 22.222222;

설명

1.8 × 1.8 = 3.24 and 72 / 3.24 ≈ 22.2222.

예시 2
입력:
weight_kg = 50.0
height_m = 1.0

예상 출력:
expected = 50.0
입력:
double weight_kg = 50.0;
double height_m = 1.0;

예상 출력:
double expected = 50.0;
입력:
double weight_kg = 50.0;
double height_m = 1.0;

예상 출력:
double expected = 50.0;

설명

With a height of 1 meter the BMI equals the weight: 50.

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

BMI compares weight to height squared, so the height term matters twice.

힌트 2

Square the height first or be careful with parentheses when dividing.

힌트 3

Use decimal division, because the answer is usually not an integer.

예상 복잡도

O(1) time, O(1) extra space

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제약 조건을 기준으로 풀어 주세요.

코더마다 가장 좋은 통과 풀이입니다. 더 빠르고, 메모리를 덜 쓰고, 평가가 좋은 풀이가 위에 옵니다.

# 코더 언어 시간 메모리 AI 평가 풀이
1 ДЗДавид Зайдулин Python 843 ms - 4/5 코드 보기
2 LMLaura Mahlow Python 860 ms - 5/5 코드 보기
3 GTGarlic The Destroyer Rust 1,238 ms - 5/5 코드 보기

다른 사람의 풀이 보기

커뮤니티 풀이

스포일러: 아래에 전체 풀이 3개가 있습니다 먼저 직접 풀어보세요. 다른 개발자의 코드와 AI 리뷰도 참고할 수 있습니다. 로그인하고 문제를 풀면 토론에 참여할 수 있습니다.