ZeroJudge D051: Oops, I have a fever!

Sansan is studying in the United States. One day, she felt uncomfortable and drowsy all over her body, wondering if she had a fever. She went to the pharmacy and bought a thermometer to measure her temperature. She found that her temperature was 104 degrees Fahrenheit. Accustomed to Celsius in Taiwan, she didn't know how high her temperature was in Celsius. Could you help her write a program to convert the temperature from Fahrenheit to Celsius?

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The input consists of a single line containing an integer F (-460 ≤ F ≤ 2147483647), representing the temperature in Fahrenheit.Output the calculated temperature in Celsius, rounded to three decimal places.
10440.000
9836.667

Thought Process

When receiving the input, you can use float or double to avoid any potential issues with negative type conversion during calculations. To convert Fahrenheit temperature to Celsius, you can use the following formula: (F - 32) * 5 / 9. For output, you can use printf("%.3f\n", ans) to ensure the temperature is rounded to three decimal places.

Sample Code-ZeroJudge D051: Oops, I have a fever!

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  double N;
  cin >> N;
  double ans = (N-32) * 5 / 9;
  printf("%.3f\n", ans);
}

//Z.O.J D051
//Dr. SeanXD

Comments