Tous les défis
Facile 0 résolus 0 % de réussite

Celsius to Fahrenheit

Convert a temperature from Celsius to Fahrenheit.

Ce que vous allez apprendre

  • Convert units with a formula
  • Work with decimal numbers
  • Keep operator precedence right

Problème

Afficher la traduction

Convert a temperature in degrees Celsius to degrees Fahrenheit using F = C × 9 / 5 + 32.

Implement celsius_to_fahrenheit(celsius).

Input

celsius: The temperature in degrees Celsius.

Output

Return the temperature in degrees Fahrenheit (a decimal number).

Contraintes

-273.15 ≤ celsius ≤ 10,000

Exemples

Exemple 1
Entrée :
celsius = 100.0

Sortie attendue :
expected = 212.0
Entrée :
double celsius = 100.0;

Sortie attendue :
double expected = 212.0;
Entrée :
double celsius = 100.0;

Sortie attendue :
double expected = 212.0;

Explication

100 × 9 / 5 + 32 = 212, the boiling point of water.

Exemple 2
Entrée :
celsius = -40.0

Sortie attendue :
expected = -40.0
Entrée :
double celsius = -40.0;

Sortie attendue :
double expected = -40.0;
Entrée :
double celsius = -40.0;

Sortie attendue :
double expected = -40.0;

Explication

-40 × 9 / 5 + 32 = -40: both scales meet at -40.

Comment l'aborder

Essayez d'abord seul, puis ouvrez les indices un par un.

Indice 1

This is a direct unit conversion from one linear scale to another.

Indice 2

Apply the given formula carefully, especially the order of multiplication and division.

Indice 3

Keep the result as a decimal value, since many inputs do not convert to integers exactly.

Complexité attendue

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

Références

Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.

Apprenez des autres

Solutions de la communauté

Aucune solution publiée pour l'instant. Résolvez ce défi pour partager la première.