Einfach 0 gelöst 0% Erfolgsquote

Body Mass Index

Compute BMI from weight and height.

Das lernst du

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

Problem

Übersetzung anzeigen

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

Einschränkungen

1 ≤ weight_kg ≤ 500; 0.5 ≤ height_m ≤ 2.5

Beispiele

Beispiel 1
Eingabe:
height_m = 1.8
weight_kg = 72.0

Erwartete Ausgabe:
expected = 22.222222
Eingabe:
double height_m = 1.8;
double weight_kg = 72.0;

Erwartete Ausgabe:
double expected = 22.222222;
Eingabe:
double height_m = 1.8;
double weight_kg = 72.0;

Erwartete Ausgabe:
double expected = 22.222222;

Erläuterung

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

Beispiel 2
Eingabe:
height_m = 1.0
weight_kg = 50.0

Erwartete Ausgabe:
expected = 50.0
Eingabe:
double height_m = 1.0;
double weight_kg = 50.0;

Erwartete Ausgabe:
double expected = 50.0;
Eingabe:
double height_m = 1.0;
double weight_kg = 50.0;

Erwartete Ausgabe:
double expected = 50.0;

Erläuterung

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

So gehst du vor

Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.

Hinweis 1

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

Hinweis 2

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

Hinweis 3

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

Erwartete Komplexität

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

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.