Đề bài
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).
Ràng buộc
-273.15 ≤ celsius ≤ 10,000
Ví dụ
Đầu vào:
celsius = 100.0
Kết quả mong đợi:
expected = 212.0
Đầu vào:
double celsius = 100.0;
Kết quả mong đợi:
double expected = 212.0;
Đầu vào:
double celsius = 100.0;
Kết quả mong đợi:
double expected = 212.0;
Giải thích
100 × 9 / 5 + 32 = 212, the boiling point of water.
Đầu vào:
celsius = -40.0
Kết quả mong đợi:
expected = -40.0
Đầu vào:
double celsius = -40.0;
Kết quả mong đợi:
double expected = -40.0;
Đầu vào:
double celsius = -40.0;
Kết quả mong đợi:
double expected = -40.0;
Giải thích
-40 × 9 / 5 + 32 = -40: both scales meet at -40.
Hướng tiếp cận
Hãy tự thử trước, sau đó mở từng gợi ý một.
Gợi ý 1
This is a direct unit conversion from one linear scale to another.
Gợi ý 2
Apply the given formula carefully, especially the order of multiplication and division.
Gợi ý 3
Keep the result as a decimal value, since many inputs do not convert to integers exactly.
Độ phức tạp mong đợi
O(1) time, O(1) extra space
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.