如何将摄氏度转换为华氏度

摄氏度到华氏度和华氏度到摄氏度的转换可能是最令人困惑的转换。但是,如果您正确理解转换过程,则可以轻松转换温度。

在本文中,您将学习如何将摄氏温度转换为华氏温度,反之亦然。

如何将摄氏温度转换为华氏温度

您可以使用以下公式将摄氏温度转换为华氏温度:

 T(°F) = T(°C) × 9/5 + 32

您需要将 °C 温度乘以 9/5 并加上 32。结果将以°F 为单位。

问题陈述

你得到一个以°C 为单位的温度数字,你需要将它转换成°F。示例 1 :让 num = 100。因此,以°F 为单位的温度 = (100 x 9/5) + 32 = 212 因此,输出为 212。示例 2 :让 num = 0。因此,以°F 为单位的温度 = (0 x 9/5) + 32 = 32 因此,输出为 32。

将摄氏温度转换为华氏温度的 C++ 程序

以下是摄氏度到华氏度转换的 C++ 程序:

 // C++ program to convert temperature in Celcius to Fahrenheit
#include <iostream>
using namespace std;
// Function to convert temperature in Celcius to Fahrenheit
float celciusToFahrenheit(float num)
{
return ((num * 9.0 / 5.0) + 32.0);
}
int main()
{
float num1 = 100.0;
cout << "Temperature in Celcius: " << num1 << endl;
cout << "Temperature in Fahrenheit: " << celciusToFahrenheit(num1) << endl;
float num2 = 0;
cout << "Temperature in Celcius: " << num2 << endl;
cout << "Temperature in Fahrenheit: " << celciusToFahrenheit(num2) << endl;
float num3 = 65.0;
cout << "Temperature in Celcius: " << num3 << endl;
cout << "Temperature in Fahrenheit: " << celciusToFahrenheit(num3) << endl;
float num4 = 150.0;
cout << "Temperature in Celcius: " << num4 << endl;
cout << "Temperature in Fahrenheit: " << celciusToFahrenheit(num4) << endl;
float num5 = 20.0;
cout << "Temperature in Celcius: " << num5 << endl;
cout << "Temperature in Fahrenheit: " << celciusToFahrenheit(num5) << endl;
return 0;
}

输出:

 Temperature in Celcius: 100
Temperature in Fahrenheit: 212
Temperature in Celcius: 0
Temperature in Fahrenheit: 32
Temperature in Celcius: 65
Temperature in Fahrenheit: 149
Temperature in Celcius: 150
Temperature in Fahrenheit: 302
Temperature in Celcius: 20
Temperature in Fahrenheit: 68

将摄氏温度转换为华氏温度的 Python 程序

以下是摄氏度到华氏度转换的 Python 程序:

 # Python program to convert temperature in Celcius to Fahrenheit
# Function to convert temperature in Celcius to Fahrenheit
def celciusToFahrenheit(num):
return ((num * 9.0 / 5.0) + 32.0)
num1 = 100.0
print("Temperature in Celcius:", num1)
print("Temperature in Fahrenheit:", celciusToFahrenheit(num1))
num2 = 0
print("Temperature in Celcius:", num2)
print("Temperature in Fahrenheit:", celciusToFahrenheit(num2))
num3 = 65.0
print("Temperature in Celcius:", num3)
print("Temperature in Fahrenheit:", celciusToFahrenheit(num3))
num4 = 150.0
print("Temperature in Celcius:", num4)
print("Temperature in Fahrenheit:", celciusToFahrenheit(num4))
num5 = 20.0
print("Temperature in Celcius:", num5)
print("Temperature in Fahrenheit:", celciusToFahrenheit(num5))

输出:

 Temperature in Celcius: 100.0
Temperature in Fahrenheit: 212.0
Temperature in Celcius: 0
Temperature in Fahrenheit: 32.0
Temperature in Celcius: 65.0
Temperature in Fahrenheit: 149.0
Temperature in Celcius: 150.0
Temperature in Fahrenheit: 302.0
Temperature in Celcius: 20.0
Temperature in Fahrenheit: 68.0

相关:如何用 5 种编程语言完成 FizzBu​​zz 挑战

将摄氏温度转换为华氏温度的 JavaScript 程序

以下是摄氏度到华氏度转换的 JavaScript 程序:

 // JavaScript program to convert temperature in Celcius to Fahrenheit
// Function to convert temperature in Celcius to Fahrenheit
function celciusToFahrenheit(num) {
return ((num * 9.0 / 5.0) + 32.0);
}

var num1 = 100.0;
document.write("Temperature in Celcius: " + num1 + "<br>");
document.write("Temperature in Fahrenheit: " + celciusToFahrenheit(num1) + "<br>");
var num2 = 0;
document.write("Temperature in Celcius: " + num2 + "<br>");
document.write("Temperature in Fahrenheit: " + celciusToFahrenheit(num2) + "<br>");
var num3 = 65.0;
document.write("Temperature in Celcius: " + num3 + "<br>");
document.write("Temperature in Fahrenheit: " + celciusToFahrenheit(num3) + "<br>");
var num4 = 150.0;
document.write("Temperature in Celcius: " + num4 + "<br>");
document.write("Temperature in Fahrenheit: " + celciusToFahrenheit(num4) + "<br>");
var num5 = 20.0;
document.write("Temperature in Celcius: " + num5 + "<br>");
document.write("Temperature in Fahrenheit: " + celciusToFahrenheit(num5) + "<br>");

输出:

 Temperature in Celcius: 100
Temperature in Fahrenheit: 212
Temperature in Celcius: 0
Temperature in Fahrenheit: 32
Temperature in Celcius: 65
Temperature in Fahrenheit: 149
Temperature in Celcius: 150
Temperature in Fahrenheit: 302
Temperature in Celcius: 20
Temperature in Fahrenheit: 68

如何将华氏温度转换为摄氏度

您可以使用以下公式将华氏温度转换为摄氏度:

 T(°C) = (T(°F) - 32) × 5/9

您需要从°F 温度中减去 32,然后乘以 5/9。结果将以°C 为单位。

问题陈述

你得到一个以°F 为单位的温度数字,你需要将它转换成°C。示例 1 :让 num = 212。因此,以°C 为单位的温度 = (212 – 32) x 5/9 = 100 因此,输出为 100。示例 2 :让 num = 32。因此,以°C 为单位的温度 = (32 – 32) x 5/9 = 0 因此,输出为 0。相关:如何找到字符的 ASCII 值?

将华氏温度转换为摄氏度的 C++ 程序

下面是华氏到摄氏度转换的 C++ 程序:

 // C++ program to convert temperature in Fahrenheit to Celcius
#include <iostream>
using namespace std;
// Function to convert temperature in Fahrenheit to Celcius
float fahrenheitToCelcius(float num)
{
return ((num - 32.0) * 5.0 / 9.0);
}
int main()
{
float num1 = 212;
cout << "Temperature in Fahrenheit: " << num1 << endl;
cout << "Temperature in Celcius: " << fahrenheitToCelcius(num1) << endl;
float num2 = 32;
cout << "Temperature in Fahrenheit: " << num2 << endl;
cout << "Temperature in Celcius: " << fahrenheitToCelcius(num2) << endl;
float num3 = 149;
cout << "Temperature in Fahrenheit: " << num3 << endl;
cout << "Temperature in Celcius: " << fahrenheitToCelcius(num3) << endl;
float num4 = 302;
cout << "Temperature in Fahrenheit: " << num4 << endl;
cout << "Temperature in Celcius: " << fahrenheitToCelcius(num4) << endl;
float num5 = 68;
cout << "Temperature in Fahrenheit: " << num5 << endl;
cout << "Temperature in Celcius: " << fahrenheitToCelcius(num5) << endl;
return 0;
}

输出:

 Temperature in Fahrenheit: 212
Temperature in Celcius: 100
Temperature in Fahrenheit: 32
Temperature in Celcius: 0
Temperature in Fahrenheit: 149
Temperature in Celcius: 65
Temperature in Fahrenheit: 302
Temperature in Celcius: 150
Temperature in Fahrenheit: 68
Temperature in Celcius: 20

将华氏温度转换为摄氏度的 Python 程序

下面是用于将华氏温度转换为摄氏度的 Python 程序:

 # Python program to convert temperature in Fahrenheit to Celcius
# Function to convert temperature in Fahrenheit to Celcius
def fahrenheitToCelcius(num):
return ((num - 32.0) * 5.0 / 9.0)
num1 = 212
print("Temperature in Fahrenheit:", num1)
print("Temperature in Celcius:", fahrenheitToCelcius(num1))
num2 = 32
print("Temperature in Fahrenheit:", num2)
print("Temperature in Celcius:", fahrenheitToCelcius(num2))
num3 = 149
print("Temperature in Fahrenheit:", num3)
print("Temperature in Celcius:", fahrenheitToCelcius(num3))
num4 = 302
print("Temperature in Fahrenheit:", num4)
print("Temperature in Celcius:", fahrenheitToCelcius(num4))
num5 = 68
print("Temperature in Fahrenheit:", num5)
print("Temperature in Celcius:", fahrenheitToCelcius(num5))

输出:

 Temperature in Fahrenheit: 212
Temperature in Celcius: 100.0
Temperature in Fahrenheit: 32
Temperature in Celcius: 0.0
Temperature in Fahrenheit: 149
Temperature in Celcius: 65.0
Temperature in Fahrenheit: 302
Temperature in Celcius: 150.0
Temperature in Fahrenheit: 68
Temperature in Celcius: 20.0

相关:如何在多种语言中找到两个数字的 LCM 和 GCD

将华氏温度转换为摄氏度的 JavaScript 程序

下面是华氏到摄氏度转换的 JavaScript 程序:

 // JavaScript program to convert temperature in Celcius to Fahrenheit
// Function to convert temperature in Celcius to Fahrenheit
function fahrenheitToCelcius(num) {
return ((num - 32.0) * 5.0 / 9.0);
}

var num1 = 212;
document.write("Temperature in Fahrenheit: " + num1 + "<br>");
document.write("Temperature in Celcius: " + fahrenheitToCelcius(num1) + "<br>");
var num2 = 32;
document.write("Temperature in Fahrenheit: " + num2 + "<br>");
document.write("Temperature in Celcius: " + fahrenheitToCelcius(num2) + "<br>");
var num3 = 149;
document.write("Temperature in Fahrenheit: " + num3 + "<br>");
document.write("Temperature in Celcius: " + fahrenheitToCelcius(num3) + "<br>");
var num4 = 302;
document.write("Temperature in Fahrenheit: " + num4 + "<br>");
document.write("Temperature in Celcius: " + fahrenheitToCelcius(num4) + "<br>");
var num5 = 68;
document.write("Temperature in Fahrenheit: " + num5 + "<br>");
document.write("Temperature in Celcius: " + fahrenheitToCelcius(num5) + "<br>");

输出:

 Temperature in Fahrenheit: 212
Temperature in Celcius: 100
Temperature in Fahrenheit: 32
Temperature in Celcius: 0
Temperature in Fahrenheit: 149
Temperature in Celcius: 65
Temperature in Fahrenheit: 302
Temperature in Celcius: 150
Temperature in Fahrenheit: 68
Temperature in Celcius: 20

将摄氏度转换为华氏度并不困难

所以,你已经知道了——现在你知道如何将摄氏度转换为华氏度——反之亦然。了解两种主要的温度类型很重要,特别是如果您在美国(或其他使用华氏温度的少数地方)和其他国家/地区进行任何类型的工作。

学习编程的最好方法是开发项目。开发项目可以帮助您成为更好的程序员。如果您是编程新手,正在寻找一些初级项目,您可以尝试开发一些项目,例如象棋游戏、计算器、数字时钟、简单网站、待办事项列表应用程序等。