C# Fahrenheit to Celsius Converter
I have given here C# code to convert from Fahrenheit to Celsius and Celsius to Fahrenheit.
Source Code
using System;
using System.Collections.Generic;
using System.Text;
namespace NP
{
class Fahrenheit_Celsius
{
static void Main(string[] args)
{
System.Console.WriteLine("Fahrenheit and Celsius Converter");
//while (true)
{
System.Console.Write("Enter a number: ");
string input = System.Console.ReadLine();
double val = Convert.ToDouble(input);
double Celsius = (val - 32.0) * 5.0 / 9.0;
double Fahrenheit = (val * (9.0 / 5.0) + 32);
System.Console.WriteLine("{0} °F = {1} °C", val.ToString("F04"), Celsius.ToString("F04"));
System.Console.WriteLine("{0} °C = {1} °F", val.ToString("F04"), Fahrenheit.ToString("F04"));
System.Console.WriteLine();
}
}
}
}
Output
|