C/C++ programming learning-week 3 ⑥ temperature expression conversion

Topic link

Title description

Little garlic garlic recently learned the conversion of Celsius and Fahrenheit.

Use the formula C = 5 × (F − 32) / 9 (where C represents the temperature in Celsius and F represents the temperature in Fahrenheit) to calculate and transform.

She wants you to write a program to complete the conversion quickly.

Input format
Input one line, including a real number F, which represents the temperature in Fahrenheit. (−459.67 ≤ F ≤ 10000)

Output format
Output one line, including a real number, representing the corresponding temperature in degrees Celsius, and it is required to be accurate to 5 decimal places.

Sample Input

41

Sample Output

5.00000

Ideas

Perform temperature conversion according to the formula given by the title.

C language code:

#include<stdio.h>
int main()
{
    
    
	double x;
	scanf("%lf", &x);
	printf("%.5lf", 5 * (x - 32) / 9);
	return 0;
}

C++ code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	double f;
	while(cin >> f)
		printf("%.5lf\n", 5 * (f - 32) / 9);
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/112860926