使用 C++ 进行华氏温度到开尔文温度转换的程序
给出华氏温度 ‘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 convert Fahrenheit to kelvin 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 ;
//convert fahrenheit to kelvin
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
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP