The Program in C++ to convert Celsius to Kelvin is given below:
#include <iostream>
using namespace std;
int main() {
double celsius, kelvin;
cout << "Enter temperature in Celsius: ";
cin >> celsius;
kelvin = celsius + 273.15;
cout << "Temperature in Kelvin: " << kelvin << endl;
return 0;
}
Output:
Enter temperature in Celsius: 45
Temperature in Kelvin: 318.15
Pro-Tips💡
In this program, we first declare two double variables: celsius to store the temperature in Celsius and kelvin to store the temperature in Kelvin.
The program prompts the user to enter a temperature in Celsius using the “cout” statement, and uses the “cin” statement to input the temperature.
Then we convert the temperature from Celsius to Kelvin by adding 273.15 to the temperature in Celsius.
Finally, the program uses the “cout” statement to output the temperature in Kelvin to the console.
It is important to note that the temperature in Celsius should be greater than or equal to -273.15, otherwise it will result in a runtime error as the Kelvin scale doesn’t go below that.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.