C++ program to convert temperature from Celsius to Kelvin

In this tutorial, we will be learning about, how to get convert temperature from Celsius to Kelvin in C++.

Kelvin and Celsius are the units of temperature we use in our day-to-day life. Celsius or Centigrade is used basically to denote the freezing point and boiling point of water. Kelvin is known as the SI unit of temperature and it is generally used to measure very low and very high temperatures.

So let’s have a look at how we can change our scale from Celsius to kelvin

For converting the scale from Celsius to Kelvin, we will add 273.15 to the Celsius and our temperature will get converted to Kelvin.

K = 273.15 + C

C++ Code: Convert the temperature from Celsius to Kelvin

#include <iostream>
using namespace std;

int main(){
    float C, K; //Keeping float values for celsius and kelvin respectively.
    
    cout << "temperature in Celsius: ";
    cin >> C;      //here we will take input from user.
    
    K = C + 273.15; //celsius to kelvin conversion takes place using this formula.
    
    cout << "temperature in the Kelvin will be : " << K <<"\n";  //kelvin temperature printed.
    return 0;
}

Output:

temperature in Celsius: 78
temperature in the Kelvin will be : 351.15

Explanation to the above code

  1. First, we have declared two float type variables C and K which represents Celsius and Kelvin respectively.
  2. Afterward, we will take input from user in Celsius scale.
  3. Then we will write the simple formula to convert Celsius to kelvin scale as written in the code.
  4. Our temperature is converted into kelvin scale and using cout statement our final output will be printed on the screen ( in Kelvin ).

Leave a Reply

Your email address will not be published.