Convert celsius to fahrenheit
Celsius and Fahrenheit are two different temperature scales used to measure temperature. Celsius is the metric system's temperature scale, while Fahrenheit is used primarily in the United States and a few other countries that have not adopted the metric system.
To convert Celsius to Fahrenheit, you can use the following formula:
Fahrenheit = Celsius * 9/5 + 32
In this formula, Fahrenheit is the temperature in degrees Fahrenheit, and Celsius is the temperature in degrees Celsius.
For example, let's say you have a temperature of 25 degrees Celsius. To convert this to Fahrenheit, you would use the formula:
Fahrenheit = 25 * 9/5 + 32 Fahrenheit = 45 + 32 Fahrenheit = 77
Therefore, 25 degrees Celsius is equivalent to 77 degrees Fahrenheit.
Program solution
//C Program
//Convert celsius to fahrenheit
#include <stdio.h>
//Find the fahrenheit of given celsius
void celsius_to_fahrenheit(double celsius)
{
// Formula : (celsius × 9/5) + 32
// Calculate given celsius to fahrenheit
double fahrenheit = (celsius * (9 / 5.0)) + 32;
//Display result
printf("Celsius : %lf Fahrenheit : %lf\n", celsius, fahrenheit);
}
int main()
{
//Simple test
celsius_to_fahrenheit(1);
celsius_to_fahrenheit(10.80);
celsius_to_fahrenheit(21.50);
return 0;
}
Output
Celsius : 1.000000 Fahrenheit : 33.800000
Celsius : 10.800000 Fahrenheit : 51.440000
Celsius : 21.500000 Fahrenheit : 70.700000
/*
Java program
Convert the celsius to fahrenheit
*/
class MyMath
{
//Find the fahrenheit of given celsius
public void celsius_to_fahrenheit(double celsius)
{
// Formula : (celsius × 9/5) + 32
// Calculate given celsius to fahrenheit
double fahrenheit = (celsius * (9 / 5.0)) + 32;
System.out.print("Celsius : " + celsius + " Fahrenheit : " + fahrenheit + "\n");
}
public static void main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
obj.celsius_to_fahrenheit(1);
obj.celsius_to_fahrenheit(10.80);
obj.celsius_to_fahrenheit(21.50);
}
}
Output
Celsius : 1.0 Fahrenheit : 33.8
Celsius : 10.8 Fahrenheit : 51.44
Celsius : 21.5 Fahrenheit : 70.7
/*
C++ program
Convert the celsius to fahrenheit
*/
#include<iostream>
using namespace std;
class MyMath
{
public:
//Find the fahrenheit of given celsius
void celsius_to_fahrenheit(double celsius)
{
// Formula : (celsius × 9/5) + 32
// Calculate given celsius to fahrenheit
double fahrenheit = (celsius * (9 / 5.0)) + 32;
cout << "Celsius : " << celsius << " Fahrenheit : " << fahrenheit << "\n";
}
};
int main()
{
MyMath obj ;
//Simple test
obj.celsius_to_fahrenheit(1);
obj.celsius_to_fahrenheit(10.80);
obj.celsius_to_fahrenheit(21.50);
return 0;
}
Output
Celsius : 1 Fahrenheit : 33.8
Celsius : 10.8 Fahrenheit : 51.44
Celsius : 21.5 Fahrenheit : 70.7
/*
C# program
Convert the celsius to fahrenheit
*/
using System;
class MyMath
{
//Find the fahrenheit of given celsius
public void celsius_to_fahrenheit(double celsius)
{
// Formula : (celsius × 9/5) + 32
// Calculate given celsius to fahrenheit
double fahrenheit = (celsius * (9 / 5.0)) + 32;
Console.Write("Celsius : " + celsius + " Fahrenheit : " + fahrenheit + "\n");
}
public static void Main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
obj.celsius_to_fahrenheit(1);
obj.celsius_to_fahrenheit(10.80);
obj.celsius_to_fahrenheit(21.50);
}
}
Output
Celsius : 1 Fahrenheit : 33.8
Celsius : 10.8 Fahrenheit : 51.44
Celsius : 21.5 Fahrenheit : 70.7
<?php
/*
Php program
Convert the celsius to fahrenheit
*/
class MyMath
{
//Find the fahrenheit of given celsius
public function celsius_to_fahrenheit($celsius)
{
// Formula : (celsius × 9/5) + 32
// Calculate given celsius to fahrenheit
$fahrenheit = ($celsius * (9 / 5.0)) + 32;
echo "Celsius : ". $celsius ." Fahrenheit : ". $fahrenheit ."\n";
}
}
function main()
{
$obj = new MyMath();
//Simple test
$obj->celsius_to_fahrenheit(1);
$obj->celsius_to_fahrenheit(10.80);
$obj->celsius_to_fahrenheit(21.50);
}
main();
Output
Celsius : 1 Fahrenheit : 33.8
Celsius : 10.8 Fahrenheit : 51.44
Celsius : 21.5 Fahrenheit : 70.7
/*
Node Js program
Convert the celsius to fahrenheit
*/
class MyMath
{
//Find the fahrenheit of given celsius
celsius_to_fahrenheit(celsius)
{
// Formula : (celsius × 9/5) + 32
// Calculate given celsius to fahrenheit
var fahrenheit = (celsius * (9 / 5.0)) + 32;
process.stdout.write("Celsius : " + celsius + " Fahrenheit : " + fahrenheit + "\n");
}
}
function main()
{
var obj = new MyMath();
//Simple test
obj.celsius_to_fahrenheit(1);
obj.celsius_to_fahrenheit(10.80);
obj.celsius_to_fahrenheit(21.50);
}
main();
Output
Celsius : 1 Fahrenheit : 33.8
Celsius : 10.8 Fahrenheit : 51.44
Celsius : 21.5 Fahrenheit : 70.7
# Python 3 program
# Convert the celsius to fahrenheit
class MyMath :
# Find the fahrenheit of given celsius
def celsius_to_fahrenheit(self, celsius) :
# Formula : (celsius × 9/5) + 32
# Calculate given celsius to fahrenheit
fahrenheit = (celsius * (9 / 5.0)) + 32
print("Celsius : ", celsius ," Fahrenheit : ", fahrenheit ,"\n", end = "")
def main() :
obj = MyMath()
# Simple test
obj.celsius_to_fahrenheit(1)
obj.celsius_to_fahrenheit(10.80)
obj.celsius_to_fahrenheit(21.50)
if __name__ == "__main__": main()
Output
Celsius : 1 Fahrenheit : 33.8
Celsius : 10.8 Fahrenheit : 51.44
Celsius : 21.5 Fahrenheit : 70.7
# Ruby program
# Convert the celsius to fahrenheit
class MyMath
# Find the fahrenheit of given celsius
def celsius_to_fahrenheit(celsius)
# Formula : (celsius × 9/5) + 32
# Calculate given celsius to fahrenheit
fahrenheit = (celsius * (9 / 5.0)) + 32
print("Celsius : ", celsius ," Fahrenheit : ", fahrenheit ,"\n")
end
end
def main()
obj = MyMath.new()
# Simple test
obj.celsius_to_fahrenheit(1)
obj.celsius_to_fahrenheit(10.80)
obj.celsius_to_fahrenheit(21.50)
end
main()
Output
Celsius : 1 Fahrenheit : 33.8
Celsius : 10.8 Fahrenheit : 51.44
Celsius : 21.5 Fahrenheit : 70.7
/*
Scala program
Convert the celsius to fahrenheit
*/
class MyMath
{
//Find the fahrenheit of given celsius
def celsius_to_fahrenheit(celsius: Double): Unit = {
// Formula : (celsius × 9/5) + 32
// Calculate given celsius to fahrenheit
var fahrenheit: Double = (celsius * (9 / 5.0)) + 32;
print("Celsius : " + celsius + " Fahrenheit : " + fahrenheit + "\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: MyMath = new MyMath();
//Simple test
obj.celsius_to_fahrenheit(1);
obj.celsius_to_fahrenheit(10.80);
obj.celsius_to_fahrenheit(21.50);
}
}
Output
Celsius : 1.0 Fahrenheit : 33.8
Celsius : 10.8 Fahrenheit : 51.44
Celsius : 21.5 Fahrenheit : 70.7
/*
Swift program
Convert the celsius to fahrenheit
*/
class MyMath
{
//Find the fahrenheit of given celsius
func celsius_to_fahrenheit(_ celsius: Double)
{
// Formula : (celsius × 9/5) + 32
// Calculate given celsius to fahrenheit
let fahrenheit: Double = (celsius * (9 / 5.0)) + 32;
print("Celsius : ", celsius ," Fahrenheit : ", fahrenheit ,"\n", terminator: "");
}
}
func main()
{
let obj: MyMath = MyMath();
//Simple test
obj.celsius_to_fahrenheit(1);
obj.celsius_to_fahrenheit(10.80);
obj.celsius_to_fahrenheit(21.50);
}
main();
Output
Celsius : 1.0 Fahrenheit : 33.8
Celsius : 10.8 Fahrenheit : 51.44
Celsius : 21.5 Fahrenheit : 70.7
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