Q:

C# program to convert a temperature from Fahrenheit into Celsius

belongs to collection: C# Basic Programs | basics

0

C# program to convert a temperature from Fahrenheit into Celsius

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to convert a Fahrenheit temperature into Celsius is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to convert a Fahrenheit temperature into Celsius.

using System;

class Program
{
    static double convertToCelsius(double ferTemp)
    {
        double cTemp = 0;

        cTemp = (ferTemp - 32) * 5 / 9;
        return cTemp;
    }
    static void Main(string[] args)
    {
        double celTemp=0;
        double ferTemp=0;
        
        Console.Write("Enter the value of temperature in Fahrenheite(°F): ");
        ferTemp = double.Parse(Console.ReadLine());

        celTemp = convertToCelsius(ferTemp);
        Console.WriteLine("Celsius temperature is(°C) : " + celTemp);
    }
}

Output:

Enter the value of temperature in Fahrenheite(°F): 90.5
Celsius temperature is(°C) : 32.5
Press any key to continue . . .

Explanation:

In the above program, we created a class Program that contains two static methods convertToCelsius() and Main(). The convertToCelsius() method is used to convert the Fahrenheit temperature into Celsius.

In the Main() method, we read the value of temperature in Fahrenheit and then convert the temperature into Celsius using convertToCelsius() method and print the result on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to create gray code... >>
<< C# program to convert a binary number into a decim...