在华氏温度为n的情况下,面临的挑战是将给定温度转换为开尔文并显示出来。
Input 1-: 549.96 Output -: Temperature in fahrenheit 549.96 to kelvin : 561.256 Input 2-: 23.45 Output -: Temperature in fahrenheit 23.45 to kelvin : 268.4
为了将温度从华氏温度转换为开氏温度,下面给出了一个公式
K = 273.5 +((F-32.0)*(5.0 / 9.0))
其中,K是开氏温度,F是华氏温度
下面使用的方法如下-
浮动变量中的输入温度,我们说华氏温度
应用公式将温度转换为开尔文
打印开尔文
Start Step 1-> Declare function to 转换华氏到开尔文 float convert(float fahrenheit) return 273.5 + ((fahrenheit - 32.0) * (5.0/9.0)) step 2-> In main() declare and set float fahrenheit = 549.96 Call convert(fahrenheit) Stop
#include<iostream> using namespace std ; //转换华氏到开尔文 float convert(float fahrenheit) { return 273.5 + ((fahrenheit - 32.0) * (5.0/9.0)); } int main() { float fahrenheit = 549.96; cout << "Temperature in fahrenheit "<<fahrenheit<<" to kelvin : "<<convert(fahrenheit) ; return 0; }
输出结果
如果我们运行以上代码,它将在输出后产生
Temperature in fahrenheit 549.96 to kelvin : 561.256