Fahrenheit or Celsius (centigrade) is a scale and unit of measurement for temperature. In United States, Fahrenheit is accepted standard for non-scientific usage and All other countries uses the Celsius as primary scale to measure temperature. In this program we will see how to convert Fahrenheit to Celsius and Celsius to Fahrenheit using standard formula.
Formula:
°F = °C x 9/5 + 32
°C = (°F - 32) x 5/9
Examples:
100°C = 212°F ( 100°C multiplied by 9/5 +32 = 212°F )
50°F = 10°C ( (50°F - 32) multiplied by 5/9 = 10°C )
VB.NET Program:
Namespace DotNetMirror
Class TempConversion
Shared Sub Main()
Console.WriteLine("/***** Fahrenheit to Celsius & Celsius to Fahrenheit Conversion Program *****/")
Dim temperatue As Double
Dim result As Double
' Fahrenheit to Celsius
Console.WriteLine("Enter temperature in Fahrenheit(°F)")
temperatue = Convert.ToDouble(Console.ReadLine())
result = ConvertF2C(temperatue)
Console.WriteLine("Converted temperature in Celsius = " & result & "°C")
' Celsius to Fahrenheit
Console.WriteLine("Enter temperature in Celsius(°C)")
temperatue = Convert.ToDouble(Console.ReadLine())
result = ConvertC2F(temperatue)
Console.WriteLine("Converted temperature in Fahrenheit = " & result & "°F")
Console.ReadLine()
End Sub
Shared Function ConvertC2F(c As Double) As Double
Return c * 9 / 5 + 32
End Function
Shared Function ConvertF2C(f As Double) As Double
Return (f - 32) * 5 / 9
End Function
End Class
End Namespace
Output:
C#.NET Program:
FYI. Same program has been converted to C# version.
namespace DotNetMirror
{
class TempConversion
{
static void Main()
{
Console.WriteLine("/***** Fahrenheit to Celsius & Celsius to Fahrenheit Conversion Program *****/");
double temperatue;
double result;
// Fahrenheit to Celsius
Console.WriteLine("Enter temperature in Fahrenheit(°F)");
temperatue = Convert.ToDouble(Console.ReadLine());
result = ConvertF2C(temperatue);
Console.WriteLine("Converted temperature in Celsius = " + result + "°C");
// Celsius to Fahrenheit
Console.WriteLine("Enter temperature in Celsius(°C)");
temperatue = Convert.ToDouble(Console.ReadLine());
result = ConvertC2F(temperatue);
Console.WriteLine("Converted temperature in Fahrenheit = " + result + "°F");
Console.ReadLine();
}
public static double ConvertC2F(double c)
{
return c * 9 / 5 + 32;
}
public static double ConvertF2C(double f)
{
return (f - 32) * 5 / 9 ;
}
}
}