Friday, March 21, 2014

Method_Ex_3 (Wk-8) Feb 24-28, 2014

Q: Write Method to convert Fahrenheit to Celsius. Pass a Fahrenheit value and return the Celsius value.
Call this method by passing it a Fahrenheit temperature from user, then display its Celsius value.
Formula: C = (F-32) * 5/9

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Method_Ex_3
{
    class Program
    {
        static void Main(string[] args)
        {
            double fahrenheit;
            Console.Write("Enter fehrenheit degree: ");
            double.TryParse(Console.ReadLine(), out fahrenheit);

            double celsius = CelsiusDegree(fahrenheit);
            Console.WriteLine("Celsius degree is: {0}", celsius.ToString("f3"));

            Console.ReadKey();
        }
        static double CelsiusDegree(double f)
        {
            double c = (f - 32) * 5 / 9;
            return c;
        }
    }
}


No comments:

Post a Comment