Program for Fahrenheit to Kelvin conversion

24 May, 2022
Given a Temperature in Fahrenheit scale, our task is to convert it into Kelvin scale.Examples :  
Input : F = 100
Output : K = 311.278

Input : F = 110
Output : K = 316.833
 
The temperature conversion from Fahrenheit ( F ) to Kelvin ( K ) is given by the formula :  
K = 273.5 + ((F - 32.0) * (5.0/9.0))
 
C++
Java
Python
C#
PHP
Javascript
// CPP program to convert temperature from// Fahrenheit to Kelvin#include<iostream>using namespace std ; // Function to convert temperature from degree// Fahrenheit to Kelvinfloat Fahrenheit_to_Kelvin( float F ){    return 273.5 + ((F - 32.0) * (5.0/9.0));} // Driver functionint main(){    float F = 100;    cout << "Temperature in Kelvin ( K ) = "          << Fahrenheit_to_Kelvin( F ) ;    return 0;}
// Java program to convert temperature// from Fahrenheit to Kelvinclass GFG{ // Function to convert temperature // from degree Fahrenheit to Kelvinstatic float Fahrenheit_to_Kelvin( float F ){    return 273.5f + ((F - 32.0f) * (5.0f/9.0f));} // Driver codepublic static void main(String arg[]){    float F = 100;    System.out.print("Temperature in Kelvin ( K ) = "                    + (Math.round(Fahrenheit_to_Kelvin( F )                                        *1000.0)/1000.0)) ;}}// This code is contributed by Anant Agarwal.
# Python program to convert temperature from# Fahrenheit to Kelvin # Function to convert temperaturedef Fahrenheit_to_Kelvin(F):    return 273.5 + ((F - 32.0) * (5.0/9.0)) # Driver functionF = 100print("Temperature in Kelvin ( K ) = {:.3f}"            .format(Fahrenheit_to_Kelvin( F )))
// C# program to convert temperature// from Fahrenheit to Kelvinusing System; class GFG{ // Function to convert temperature// from degree Fahrenheit to Kelvinstatic float Fahrenheit_to_Kelvin( float F ){    return 273.5f + ((F - 32.0f) *                    (5.0f/9.0f));} // Driver codepublic static void Main(){    float F = 100;    Console.WriteLine("Temperature in Kelvin (K) = "                    + (Math.Round(Fahrenheit_to_Kelvin(F)                                        *1000.0)/1000.0)) ;}} // This code is contributed by vt_m.
<?php// PHP program to convert temperature// from Fahrenheit to Kelvin // Function to convert temperature// from degree  Fahrenheit to Kelvinfunction Fahrenheit_to_Kelvin( $F ){    return 273.5 + (($F - 32.0) *                    (5.0 / 9.0));}     // Driver Code    $F = 100;    $x = number_format(Fahrenheit_to_Kelvin($F), 3);    echo "Temperature in Kelvin ( K ) = ".$x;     // This code is contributed by Sam007?>
<script> // Javascript program to convert temperature from// Fahrenheit to Kelvin // Function to convert temperature from degree// Fahrenheit to Kelvinfunction Fahrenheit_to_Kelvin( F ){    return 273.5 + ((F - 32.0) * (5.0/9.0));} // Driver function     let F = 100;    document.write("Temperature in Kelvin ( K ) = "        + Fahrenheit_to_Kelvin( F )) ; // This code is contributed Mayank Tyagi </script>
Output : 
Temperature in Kelvin ( K ) = 311.278
Time Complexity: O(1), as we are not using any loops.
Auxiliary Space: O(1), as we are not using any extra space. 
vt_m
Sam007
mayanktyagi1709
rohitsingh07052
School Programming
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.