c++ program to convert kelvin to celsius

#include <iostream>
using namespace std;

int main() {
    double kelvin, celsius;
    cout << "Enter temperature in Kelvin: ";
    cin >> kelvin;
    celsius = kelvin - 273.15;
    cout << "Temperature in Celsius: " << celsius << endl;
    return 0;
}

Explanation

  1. The #include <iostream> line includes the necessary header file for input and output operations in C++.

  2. The using namespace std; line allows us to use names from the std namespace without specifying the namespace each time. This is done to avoid writing std:: before cout, cin, etc.

  3. The int main() function is the entry point of the program. It is where the execution of the program begins.

  4. Inside the main() function, we declare two variables kelvin and celsius of type double. These variables will be used to store the temperature values.

  5. The cout << "Enter temperature in Kelvin: "; statement outputs the message asking the user to enter the temperature in Kelvin.

  6. The cin >> kelvin; statement reads the user input from the standard input and stores it in the kelvin variable.

  7. The celsius = kelvin - 273.15; statement calculates the temperature in Celsius by subtracting 273.15 from the Kelvin temperature.

  8. The cout << "Temperature in Celsius: " << celsius << endl; statement outputs the temperature in Celsius.

  9. The return 0; statement indicates that the program has completed successfully and returns the value 0 to the operating system.

The program takes the input temperature in Kelvin, subtracts 273.15 to convert it to Celsius, and then outputs the converted temperature in Celsius.