Convert fahrenheit to kelvin

Here given code implementation process.

//C Program 
//Convert fahrenheit to kelvin
#include <stdio.h>

//Find the kelvin by given fahrenheit
void fahrenheit_to_kelvin(double fahrenheit)
{
	// Formula :  (fahrenheit - 32) × 5/9 + 273.15 
	// Calculate given fahrenheit to kelvin 
	double kelvin = (fahrenheit - 32) * (5 / 9.0) + 273.15;
	//Display result
	printf("Fahrenheit : %lf  Kelvin : %lf\n", fahrenheit, kelvin);
}
int main()
{
	//Simple test
	fahrenheit_to_kelvin(1);
	fahrenheit_to_kelvin(14.5);
	fahrenheit_to_kelvin(52.9);
	return 0;
}

Output

Fahrenheit : 1.000000  Kelvin : 255.927778
Fahrenheit : 14.500000  Kelvin : 263.427778
Fahrenheit : 52.900000  Kelvin : 284.761111
/*
  Java program
  Convert fahrenheit to kelvin
*/
class MyMath
{
	//Find the kelvin by given fahrenheit
	public void fahrenheit_to_kelvin(double fahrenheit)
	{
		// Formula : (fahrenheit - 32) × 5/9 + 273.15 
		// Calculate given fahrenheit to kelvin 
		double kelvin = (fahrenheit - 32) * (5 / 9.0) + 273.15;
		System.out.print("Fahrenheit : " + fahrenheit + " Kelvin : " + kelvin + "\n");
	}
	public static void main(String[] args)
	{
		MyMath obj = new MyMath();
		//Simple test
		obj.fahrenheit_to_kelvin(1);
		obj.fahrenheit_to_kelvin(14.5);
		obj.fahrenheit_to_kelvin(52.9);
	}
}

Output

Fahrenheit : 1.0 Kelvin : 255.92777777777775
Fahrenheit : 14.5 Kelvin : 263.42777777777775
Fahrenheit : 52.9 Kelvin : 284.76111111111106
/*
  C++ program
  Convert fahrenheit to kelvin
*/
#include<iostream>

using namespace std;
class MyMath
{
	public:
		//Find the kelvin by given fahrenheit
		void fahrenheit_to_kelvin(double fahrenheit)
		{
			// Formula : (fahrenheit - 32) × 5/9 + 273.15 
			// Calculate given fahrenheit to kelvin 
			double kelvin = (fahrenheit - 32) * (5 / 9.0) + 273.15;
			cout << "Fahrenheit : " << fahrenheit << " Kelvin : " << kelvin << "\n";
		}
};
int main()
{
	MyMath obj ;
	//Simple test
	obj.fahrenheit_to_kelvin(1);
	obj.fahrenheit_to_kelvin(14.5);
	obj.fahrenheit_to_kelvin(52.9);
	return 0;
}

Output

Fahrenheit : 1 Kelvin : 255.928
Fahrenheit : 14.5 Kelvin : 263.428
Fahrenheit : 52.9 Kelvin : 284.761
/*
  C# program
  Convert fahrenheit to kelvin
*/
using System;
class MyMath
{
	//Find the kelvin by given fahrenheit
	public void fahrenheit_to_kelvin(double fahrenheit)
	{
		// Formula : (fahrenheit - 32) × 5/9 + 273.15 
		// Calculate given fahrenheit to kelvin 
		double kelvin = (fahrenheit - 32) * (5 / 9.0) + 273.15;
		Console.Write("Fahrenheit : " + fahrenheit + " Kelvin : " + kelvin + "\n");
	}
	public static void Main(String[] args)
	{
		MyMath obj = new MyMath();
		//Simple test
		obj.fahrenheit_to_kelvin(1);
		obj.fahrenheit_to_kelvin(14.5);
		obj.fahrenheit_to_kelvin(52.9);
	}
}

Output

Fahrenheit : 1 Kelvin : 255.927777777778
Fahrenheit : 14.5 Kelvin : 263.427777777778
Fahrenheit : 52.9 Kelvin : 284.761111111111
<?php
/*
  Php program
  Convert fahrenheit to kelvin
*/
class MyMath
{
	//Find the kelvin by given fahrenheit
	public	function fahrenheit_to_kelvin($fahrenheit)
	{
		// Formula : (fahrenheit - 32) × 5/9 + 273.15 
		// Calculate given fahrenheit to kelvin 
		$kelvin = ($fahrenheit - 32) * (5 / 9) + 273.15;
		echo "Fahrenheit : ". $fahrenheit ." Kelvin : ". $kelvin ."\n";
	}
}

function main()
{
	$obj = new MyMath();
	//Simple test
	$obj->fahrenheit_to_kelvin(1);
	$obj->fahrenheit_to_kelvin(14.5);
	$obj->fahrenheit_to_kelvin(52.9);
}
main();

Output

Fahrenheit : 1 Kelvin : 255.92777777778
Fahrenheit : 14.5 Kelvin : 263.42777777778
Fahrenheit : 52.9 Kelvin : 284.76111111111
/*
  Node Js program
  Convert fahrenheit to kelvin
*/
class MyMath
{
	//Find the kelvin by given fahrenheit
	fahrenheit_to_kelvin(fahrenheit)
	{
		// Formula : (fahrenheit - 32) × 5/9 + 273.15 
		// Calculate given fahrenheit to kelvin 
		var kelvin = (fahrenheit - 32) * (5 / 9) + 273.15;
		process.stdout.write("Fahrenheit : " + fahrenheit + " Kelvin : " + kelvin + "\n");
	}
}

function main()
{
	var obj = new MyMath();
	//Simple test
	obj.fahrenheit_to_kelvin(1);
	obj.fahrenheit_to_kelvin(14.5);
	obj.fahrenheit_to_kelvin(52.9);
}
main();

Output

Fahrenheit : 1 Kelvin : 255.92777777777775
Fahrenheit : 14.5 Kelvin : 263.42777777777775
Fahrenheit : 52.9 Kelvin : 284.76111111111106
#   Python 3 program
#   Convert fahrenheit to kelvin

class MyMath :
	# Find the kelvin by given fahrenheit
	def fahrenheit_to_kelvin(self, fahrenheit) :
		#  Formula : (fahrenheit - 32) × 5/9 + 273.15 
		#  Calculate given fahrenheit to kelvin 
		kelvin = (fahrenheit - 32) * (5 / 9) + 273.15
		print("Fahrenheit : ", fahrenheit ," Kelvin : ", kelvin ,"\n", end = "")
	

def main() :
	obj = MyMath()
	# Simple test
	obj.fahrenheit_to_kelvin(1)
	obj.fahrenheit_to_kelvin(14.5)
	obj.fahrenheit_to_kelvin(52.9)

if __name__ == "__main__": main()

Output

Fahrenheit :  1  Kelvin :  255.92777777777775
Fahrenheit :  14.5  Kelvin :  263.42777777777775
Fahrenheit :  52.9  Kelvin :  284.76111111111106
#   Ruby program
#   Convert fahrenheit to kelvin

class MyMath

	# Find the kelvin by given fahrenheit
	def fahrenheit_to_kelvin(fahrenheit)
	
		#  Formula : (fahrenheit - 32) × 5/9 + 273.15 
		#  Calculate given fahrenheit to kelvin 
		kelvin = (fahrenheit - 32) * (5 / 9.0) + 273.15
		print("Fahrenheit : ", fahrenheit ," Kelvin : ", kelvin ,"\n")
	end
end
def main()

	obj = MyMath.new()
	# Simple test
	obj.fahrenheit_to_kelvin(1)
	obj.fahrenheit_to_kelvin(14.5)
	obj.fahrenheit_to_kelvin(52.9)
end
main()

Output

Fahrenheit : 1 Kelvin : 255.92777777777775
Fahrenheit : 14.5 Kelvin : 263.42777777777775
Fahrenheit : 52.9 Kelvin : 284.76111111111106
/*
  Scala program
  Convert fahrenheit to kelvin
*/
class MyMath
{
	//Find the kelvin by given fahrenheit
	def fahrenheit_to_kelvin(fahrenheit: Double): Unit = {
		// Formula : (fahrenheit - 32) × 5/9 + 273.15 
		// Calculate given fahrenheit to kelvin 
		var kelvin: Double = (fahrenheit - 32) * (5 / 9.0) + 273.15;
		print("Fahrenheit : " + fahrenheit + " Kelvin : " + kelvin + "\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: MyMath = new MyMath();
		//Simple test
		obj.fahrenheit_to_kelvin(1);
		obj.fahrenheit_to_kelvin(14.5);
		obj.fahrenheit_to_kelvin(52.9);
	}
}

Output

Fahrenheit : 1.0 Kelvin : 255.92777777777775
Fahrenheit : 14.5 Kelvin : 263.42777777777775
Fahrenheit : 52.9 Kelvin : 284.76111111111106
/*
  Swift program
  Convert fahrenheit to kelvin
*/
class MyMath
{
	//Find the kelvin by given fahrenheit
	func fahrenheit_to_kelvin(_ fahrenheit: Double)
	{
		// Formula : (fahrenheit - 32) × 5/9 + 273.15 
		// Calculate given fahrenheit to kelvin 
		let kelvin: Double = (fahrenheit - 32) * (5 / 9) + 273.15;
		print("Fahrenheit : ", fahrenheit ," Kelvin : ", kelvin ,"\n", terminator: "");
	}
}
func main()
{
	let obj: MyMath = MyMath();
	//Simple test
	obj.fahrenheit_to_kelvin(1);
	obj.fahrenheit_to_kelvin(14.5);
	obj.fahrenheit_to_kelvin(52.9);
}
main();

Output

Fahrenheit :  1.0  Kelvin :  255.927777777778
Fahrenheit :  14.5  Kelvin :  263.427777777778
Fahrenheit :  52.9  Kelvin :  284.761111111111

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved