w3resource

C++ Exercises: Convert temperature in Kelvin to Fahrenheit


Kelvin to Fahrenheit Conversion

Write a program in C++ to convert temperature in Kelvin to Fahrenheit.

Visual Presentation:

C++ Exercises: Convert temperature in Kelvin to Fahrenheit

Sample Solution:

C++ Code :

#include <iostream> // Including the input-output stream header file

using namespace std; // Using the standard namespace

int main() // Start of the main function
{
    float kel, frh; // Declaring floating-point variables for Kelvin and Fahrenheit temperatures

    cout << "\n\n Convert temperature in Kelvin to Fahrenheit :\n"; // Outputting a message indicating temperature conversion
    cout << "---------------------------------------------------\n"; // Outputting a separator line

    cout << " Input the temperature in Kelvin : "; // Prompting the user to input the temperature in Kelvin
    cin >> kel; // Taking input for the temperature in Kelvin from the user

    frh = (9.0 / 5) * (kel - 273.15) + 32; // Converting Kelvin to Fahrenheit using the conversion formula

    cout << " The temperature in Kelvin    : " << kel << endl; // Displaying the input temperature in Kelvin
    cout << " The temperature in Fahrenheit : " << frh << endl; // Displaying the converted temperature in Fahrenheit
    cout << endl; // Outputting a blank line for better readability

    return 0; // Returning 0 to indicate successful program execution
} // End of the main function

Sample Output:

 Convert temperature in Kelvin to Fahrenheit  :                        
---------------------------------------------------                    
 Input the temperature in Kelvin : 300                                 
 The temperature in Kelvin    : 300                                    
 The temperature in Fahrenheit : 80.33

Flowchart:

Flowchart: Convert temperature in Kelvin to Fahrenheit

For more Practice: Solve these Related Problems:

  • Write a C++ program to convert temperature from Kelvin to Fahrenheit and check for negative Kelvin inputs.
  • Write a C++ program that reads a Kelvin temperature, converts it to Fahrenheit using a function, and prints both values.
  • Write a C++ program to convert Kelvin to Fahrenheit and then display the result along with a weather description based on the temperature.
  • Write a C++ program that converts an array of Kelvin temperatures to Fahrenheit and displays them in a neatly formatted list.

Go to:


PREV : Kilometers to Miles Conversion.
NEXT : Kelvin to Celsius Conversion.

C++ Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.