簡単 0件解決済み 正答率0%

Celsius to Fahrenheit

Convert a temperature from Celsius to Fahrenheit.

このチャレンジで学べること

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

問題

翻訳を表示

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

制約

-273.15 ≤ celsius ≤ 10,000

例

例 1
入力:
celsius = 100.0

期待される出力:
expected = 212.0
入力:
double celsius = 100.0;

期待される出力:
double expected = 212.0;
入力:
double celsius = 100.0;

期待される出力:
double expected = 212.0;

解説

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

例 2
入力:
celsius = -40.0

期待される出力:
expected = -40.0
入力:
double celsius = -40.0;

期待される出力:
double expected = -40.0;
入力:
double celsius = -40.0;

期待される出力:
double expected = -40.0;

解説

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

解き方のヒント

まずは自分で考えてから、ヒントを 1 つずつ開いてみましょう。

ヒント 1

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

ヒント 2

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

ヒント 3

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

目安の計算量

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

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。