c++ program to convert kelvin to fahrenheit
#include <iostream>
using namespace std;
int main() {
float kelvin, fahrenheit;
cout << "Enter temperature in Kelvin: ";
cin >> kelvin;
fahrenheit = (kelvin - 273.15) * 9/5 + 32;
cout << "Temperature in Fahrenheit: " << fahrenheit;
return 0;
}
Explanation:
- The program starts by including the necessary header file
iostream
, which provides input/output stream functionalities. - The
using namespace std;
statement allows us to use the standard library without explicitly specifying thestd
namespace. - The
main()
function is the entry point of the program. - Two variables
kelvin
andfahrenheit
are declared asfloat
to store the temperature values. - The
cout
statement is used to display the prompt message asking the user to enter the temperature in Kelvin. - The
cin
statement reads the user input and stores it in thekelvin
variable. - The conversion formula
(kelvin - 273.15) * 9/5 + 32
is used to convert Kelvin to Fahrenheit and the result is stored in thefahrenheit
variable. - The
cout
statement is used to display the temperature in Fahrenheit. - Finally, the
return 0;
statement is used to indicate the successful execution of the program.