temperature conversion

C# program to convert Fahrenheit to Celsius

C# program to convert Fahrenheit to Celsius

In this article, we will discuss the concept of the C# program to convert Fahrenheit to Celsius

In this post, we will learn how to write a program to Convert Fahrenheit into Celsius. Celsius is calculated, and display the result on the screen using Fahrenheit value 

Here, we have four methods and explain how to calculate Celsius using the given Fahrenheit value and display the result on the screen in C# programming language.

Code to Convert Fahrenheit into Celsius

Convert Fahrenheit into Celsius  -#1

In this program, the user declares two variables as Celsius and Fahrenheit and initiates the value as 100.40 to Celsius. Then the scientific equation will convert it from Fahrenheit into Celsius in the C# programming language.

Program 1

// C# program to convert Fahrenheit to Celsius
using System;
namespace temperature
{
public class FahretoCels
{
    public static void Main(string[] args)
    {
        double celsius,fahrenheit; 
      //Declare variables
        fahrenheit=100.40;
    //initialize value to fahrenheit
        celsius=((fahrenheit-32)*5/9);
      //Caculate celsius
        Console.WriteLine ("temperature in celsius: "+celsius);
    //Display result
        Console.ReadKey();
    }
}
}

When the above code is executed, it produces the following result

The temperature in Celsius: 38

 

Convert Fahrenheit into Celsius  -Entered by the user-#2

In this program, the user declares two variables as Celsius and Fahrenheit. The program asks for the value from the user to Fahrenheit then the given input will convert from Fahrenheit into Celsius in the C# programming language using the scientific equation.

Program 2

// C# program to convert Fahrenheit to Celsius
using System;
namespace temperature
{
public class FtoC
{
    public static void Main(string[] args)
    {
        double celsius,fahrenheit; 
    //Declare variables
        Console.WriteLine ("Enter temperature in Fahrenheit: ");
        //Ask input from user for Fahrenheit
    fahrenheit=Convert.ToDouble(Console.ReadLine());
      //Reading the input
        celsius=((fahrenheit-32)*5/9);
    //Caculate Fahrenheit
        Console.WriteLine ("temperature in celsius: "+celsius);
        Console.ReadKey();
    }
}
}

When the above code is executed, it produces the following result

Enter temperature in Fahrenheit:
98.4
The temperature in Celsius: 36.8888888888889

 

Convert Fahrenheit into Celsius  -Using function-#3

In this program, the user declares a double variable as a parameter for Fahrenheit in the user-defined function. When the user runs the program (when calling the function), the value for Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation in the C# programming language..

Program 3

// C# program to convert Fahrenheit to Celsius
//using function
using System;
namespace Temperature
{
public class TempFahreToCels
{
    public static void Main(string[] args)
    {
    //Calling the function with an argument
        double celsius=celsiusToFahrenheit(200.10);
        double celsius1=celsiusToFahrenheit(212);
        double celsius2=celsiusToFahrenheit(32);
     //Display result on the screen
        Console.WriteLine ("The temperature in Celsius: "+celsius);
        Console.WriteLine ("The temperature in Celsius: "+celsius1);
        Console.WriteLine ("The temperature in Celsius: "+celsius2);
        Console.ReadLine();
    }
  //function definition
  private static double celsiusToFahrenheit(double fahrenheit)
  {
  return (((fahrenheit-32)*5)/9);
}
}
}

When the above code is executed, it produces the following result

The temperature in Celsius: 93.3888888888889
The temperature in Celsius: 100
The temperature in Celsius: 0

 

Convert Fahrenheit into Celsius Using the function-Entered by the user-#4

In this program, the user declares a double variable as a parameter for Fahrenheit in the user-defined function. When the user runs the program (when calling the function), The program asks for the value from the user to Fahrenheit and the value for Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation.

Program 4

// C# program to convert Fahrenheit to Celsius
//using function
using System;
namespace Temperature
{
public class TempFahreToCels
{
    public static void Main(string[] args)
    {
        Console.WriteLine ("Enter temperature in Fahrenheit: ");
    //Ask for input from the user
    double fahrenheit=Convert.ToDouble(Console.ReadLine());
    //Reading the input
        double celsius=FahrenheitTocelsius(fahrenheit);
      //Calling the function with an argument
        Console.WriteLine ("The temperature in Celsius: "+celsius);
    //Display result on the screen
        Console.ReadLine();
    }
  //function definition
  private static double FahrenheitTocelsius(double fahrenheit)
  {
  return ((fahrenheit-32)*5/9);
}
}
}

When the above code is executed, it produces the following result

Enter temperature in Fahrenheit:
32
The temperature in Celsius: 0

 

Similar post

Celsius into Fahrenheit in the C program

Fahrenheit into Celsius in C program

Celsius into Fahrenheit in C++ program

Fahrenheit into Celsius in C++ program

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.