Given temperature in degree Celsius, convert it into to Kelvin .
Examples:
Input : C = 100
Output : k = 373.15
Input : C = 110
Output : k = 383.15
Formula for converting temperature in degree Celsius to kelvin-
K = ( °C + 273.15 )
0 °C = 273.15 kelvin
Below is the program for temperature conversion:
C
#include <stdio.h>
float celsius_to_kelvin( float c)
{
return (c + 273.15);
}
int main()
{
float c = 50;
printf ( "Temperature in Kelvin(K) : %0.2f" ,celsius_to_kelvin(c));
return 0;
}
|
C++
#include <bits/stdc++.h>
using namespace std;
float Celsius_to_Kelvin( float C)
{
return (C + 273.15);
}
int main()
{
float C = 100;
cout << "Temperature in Kelvin ( K ) = "
<< Celsius_to_Kelvin(C);
return 0;
}
|
Java
import java.io.*;
class GFG {
static float Celsius_to_Kelvin( float C)
{
return ( float )(C + 273.15 );
}
public static void main (String[] args)
{
float C = 100 ;
System .out.println ( "Temperature in Kelvin ( K ) = "
+ Celsius_to_Kelvin(C));
}
}
|
Python3
def Celsius_to_Kelvin(C):
return (C + 273.15 )
C = 100
print ( "Temperature in Kelvin ( K ) = " ,
Celsius_to_Kelvin(C))
|
C#
using System;
class GFG {
static float Celsius_to_Kelvin( float C)
{
return ( float )(C + 273.15);
}
public static void Main()
{
float C = 100;
Console.WriteLine( "Temperature in Kelvin ( K ) = " +
Celsius_to_Kelvin(C));
}
}
|
PHP
<?php
function Celsius_to_Kelvin( $C )
{
return ( $C + 273.15);
}
$C = 100;
echo "Temperature in Kelvin ( K ) = "
, Celsius_to_Kelvin( $C );
?>
|
Javascript
<script>
function Celsius_to_Kelvin(C)
{
return (C + 273.15);
}
let C = 100;
document.write( "Temperature in Kelvin ( K ) = "
+ Celsius_to_Kelvin(C));
</script>
|
Output:
Temperature in Kelvin ( K ) = 373.15
Time Complexity: O(1), as we are not using any loops.
Auxiliary Space: O(1), as we are not using any extra space.