Hello Learner
Contributor
Stats
 Views : 81649 Comments : 0 Rating : 0
Actions

# VB.NET/C# program to convert Fahrenheit to Celsius and Celsius to Fahrenheit

By Ashok Nalam on 28 Jun 2013 | Category: VB.NET |
This program(VB.NET/C# versions) converts temperature from Fahrenheit to Celsius and Celsius to Fahrenheit.
 Rate this resource

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)")
result = ConvertF2C(temperatue)
Console.WriteLine("Converted temperature in Celsius = " & result & "°C")
'  Celsius to Fahrenheit
Console.WriteLine("Enter temperature in Celsius(°C)")
result = ConvertC2F(temperatue)
Console.WriteLine("Converted temperature in Fahrenheit = " & result & "°F")
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```

#### 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)");
result = ConvertF2C(temperatue);
Console.WriteLine("Converted temperature in Celsius = " + result + "°C");
//  Celsius to Fahrenheit
Console.WriteLine("Enter temperature in Celsius(°C)");
result = ConvertC2F(temperatue);
Console.WriteLine("Converted temperature in Fahrenheit = " + result + "°F");
}
public static double ConvertC2F(double c)
{
return c * 9 / 5 + 32;
}
public static double ConvertF2C(double f)
{
return (f - 32) * 5 / 9 ;
}
}
}```
 Rate this resource