簡単 5件解決済み 正答率100.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用に調整されています。上記の説明と制約に従ってください。

ランキング

全体ランキング

コーダーごとのいちばん良い合格解答です。速く、メモリが少なく、評価が高い解答ほど上位になります。

# コーダー 言語 時間 メモリ AI 評価 解答
1 HJhettory Jurash Python 780 ms - 5/5 コードを見る
2 LMLaura Mahlow Python 860 ms - 5/5 コードを見る
3 KKKaneki Ken Python 870 ms - 5/5 コードを見る
4 УУмар Python 1,108 ms - 5/5 コードを見る
5 NNNhân Nguyễn Thiện C++ 3,218 ms - 5/5 コードを見る

他の人の解答から学ぶ

コミュニティの解答

ネタバレ注意:下に5件の全解答あり まずは自分で挑戦してみましょう。他の開発者のコードやAIレビューも見ることができます。 サインインして課題を解くと議論に参加できます。