C program to convert Celsius to Kelvin

In this article, we are going to discuss how to convert the temperature from celsius to kelvin. Before starting the main program, we have to know about the basic formula to convert the temperature from celsius to kelvin.

C program to convert celsius to kelvin

For example –

Input-

So first step we are going to take input from the user in the form of celsius. Suppose we take 200 as user input.

Logic-

So to calculate the temperature from celsius to kelvin we have to know about the logic behind it.

So basically the formula is :

kelvin = celsius + 273.15

Output-

According to our input, we get output as

Enter the temperature in celsius:200
The temperature in kelvin is 473.149994

By using the above formula we are going to convert the temperature from celsius to kelvin so let’s try to implement this above formula in our program.

Method -1

#C program to convert the temperature from celsius to kelvin

#include<stdio.h>
int main()
{
float celsius, kelvin;
printf(“Enter the temperature in celsius :” );
scanf(“%f”, &celsius);
kelvin = celsius + 273.15;
printf(“Temperature in kelvin is %f”, kelvin);
return 0;
}

Output :

Enter the temperature in celsius:200
The temperature in kelvin is 473.149994

The above program is very simple to convert the temperature from celsius to kelvin, but now we are going to learn this program by using the user-define function so let’s start!

Method 2

// C program to convert the temperature from celsius to kelvin

#include<stdio.h>
float temperature(float celsius){
return (celsius + 273.15);
}
int main()
{
float celsius, kelvin;
printf(“Enter the temperature in celsius :” );
scanf(“%f”, &celsius);
printf(“Temperature in kelvin is %f”,temperature(celsius));
return 0;
}

Output :

Enter the temperature in celsius:20
The temperature in kelvin is 293.149994

In this above program, we can see that we simply use a user-defined function in it. Where we give the name temperature to the function after that we simply give a parameter to the function that is kelvin after that we simply apply the formula. In this way, we simply use user-defined functions. And by using these we simply get our final output.

I hope these two methods are going to be helpful for you. Whenever you want to calculate the temperature from celsius to kelvin in the c program. Then you can simply use this method to convert the temperature from kelvin to celsius.