Tutte le sfide
Facile 0 risolte 0% di accettazione

Body Mass Index

Compute BMI from weight and height.

Problema

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).

Vincoli

1 ≤ weight_kg ≤ 500; 0.5 ≤ height_m ≤ 2.5

Esempi

Esempio 1
Input:
height_m = 1.8
weight_kg = 72.0

Output atteso:
expected = 22.222222
Input:
double height_m = 1.8;
double weight_kg = 72.0;

Output atteso:
double expected = 22.222222;
Input:
double height_m = 1.8;
double weight_kg = 72.0;

Output atteso:
double expected = 22.222222;

Spiegazione

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

Esempio 2
Input:
height_m = 1.0
weight_kg = 50.0

Output atteso:
expected = 50.0
Input:
double height_m = 1.0;
double weight_kg = 50.0;

Output atteso:
double expected = 50.0;
Input:
double height_m = 1.0;
double weight_kg = 50.0;

Output atteso:
double expected = 50.0;

Spiegazione

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

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.