📜  将温度从摄氏度转换为开尔文的程序

📅  最后修改于: 2022-05-13 01:57:58.730000             🧑  作者: Mango

将温度从摄氏度转换为开尔文的程序

给定以摄氏度为单位的温度,将其转换为开尔文。
例子:

Input : C = 100
Output : k = 373.15

Input : C = 110
Output : k = 383.15

以摄氏度为单位将温度转换为开尔文的公式

K = ( °C + 273.15 )
0 °C = 273.15 kelvin

下面是温度转换程序:

C
/* C Program to convert temperature from celsius to kelvin */
#include 
 
// function takes value in celsius and returns value in kelvin
float celsius_to_kelvin(float c)
{
  return (c + 273.15);
}
 
int main()
{
 
  // variable of type float holds value in celsius
  float c = 50;
 
  // passing 'c' as parameter to the function
  // printing the value in kelvin
  printf("Temperature in Kelvin(K) : %0.2f",celsius_to_kelvin(c));
  return 0;
}


C++
// CPP program to convert temperature
// from degree Celsius to kelvin
#include 
using namespace std;
 
// function to convert temperature
// from degree Celsius to Kelvin
float Celsius_to_Kelvin(float C)
{
    return (C + 273.15);
}
 
// driver function
int main()
{
    // variable to hold the
    // temperature in Celsius
    float C = 100;
 
    cout << "Temperature in Kelvin ( K ) = "
         << Celsius_to_Kelvin(C);
     
    return 0;
}


Java
// Java program to convert temperature
// from degree Celsius to kelvin
import java.io.*;
 
class GFG {
    // function to convert temperature
    // from degree Celsius to Kelvin
    static float Celsius_to_Kelvin(float C)
    {
        return (float)(C + 273.15);
    }
     
    // Driver function
    public static void main (String[] args)
    {
        // variable to hold the
        // temperature in Celsius
        float C = 100;
     
        System .out.println ( "Temperature in Kelvin ( K ) = "
                             + Celsius_to_Kelvin(C));
             
    }
}
 
// This code is contributed by vt_m.


Python3
# Python3 program to convert temperature
# from degree Celsius to kelvin
 
# Function to convert temperature
# from degree Celsius to Kelvin
def Celsius_to_Kelvin(C):
    return (C + 273.15)
 
# Driver Code
 
# variable to hold the
# temperature in Celsius
C = 100
 
print("Temperature in Kelvin ( K ) = ",
                    Celsius_to_Kelvin(C))
                     
# This code is contributed by Anant Agarwal.


C#
// C# program to convert temperature
// from degree Celsius to kelvin
using System;
 
class GFG {
     
    // function to convert temperature
    // from degree Celsius to Kelvin
    static float Celsius_to_Kelvin(float C)
    {
        return (float)(C + 273.15);
    }
 
    // Driver function
    public static void Main()
    {
        // variable to hold the
        // temperature in Celsius
        float C = 100;
 
        Console.WriteLine("Temperature in Kelvin ( K ) = " +
                                       Celsius_to_Kelvin(C));
    }
}
 
// This code is contributed by vt_m.


PHP


Javascript


输出:

Temperature in Kelvin ( K ) = 373.15