โจทย์
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
อินพุต:
height_m = 1.8
weight_kg = 72.0
ผลลัพธ์ที่คาดหวัง:
expected = 22.222222
อินพุต:
double height_m = 1.8;
double weight_kg = 72.0;
ผลลัพธ์ที่คาดหวัง:
double expected = 22.222222;
อินพุต:
double height_m = 1.8;
double weight_kg = 72.0;
ผลลัพธ์ที่คาดหวัง:
double expected = 22.222222;
คำอธิบาย
1.8 × 1.8 = 3.24 and 72 / 3.24 ≈ 22.2222.
ตัวอย่างที่ 2
อินพุต:
height_m = 1.0
weight_kg = 50.0
ผลลัพธ์ที่คาดหวัง:
expected = 50.0
อินพุต:
double height_m = 1.0;
double weight_kg = 50.0;
ผลลัพธ์ที่คาดหวัง:
double expected = 50.0;
อินพุต:
double height_m = 1.0;
double weight_kg = 50.0;
ผลลัพธ์ที่คาดหวัง:
double expected = 50.0;
คำอธิบาย
With a height of 1 meter the BMI equals the weight: 50.
แหล่งอ้างอิง
โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน