Celsius To Fahrenheit Conversions And Vice-Versa

In this blog, we will discuss how to write a program that will convert the Celsius temperature into Fahrenheit and vice-versa.

Temperature is measured by using different units, like Celsius, Fahrenheit, and Kelvin. Here, we will see how to convert a Celsius temperature to Fahrenheit temperature and vice-versa.

First, open Visual Studio IDE and then create a project in Console app. Write the following code in the project.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. namespace Celsius_to_Fahrenheit_consversion {  
  7.     class Program {  
  8.         static void Main(string[] args) {  
  9.             double f, c;  
  10.             Console.WriteLine("Enter the value of Celsius:");  
  11.             c = Convert.ToDouble(Console.ReadLine());  
  12.             f = c * 9 / 5 + 32;  
  13.             Console.WriteLine(c + "°C in Fahrenheit is: " + f + "°F");  
  14.             Console.WriteLine("Enter the value of Fahrenheit:");  
  15.             f = Convert.ToDouble(Console.ReadLine());  
  16.             c = (f - 32) * 5 / 9;  
  17.             Console.WriteLine(f + "°F in Celsius is: " + c + "°C");  
  18.             Console.ReadLine();  
  19.         }  
  20.     }  
  21. }  
Then, a screen will appear like this.

C#

After writing the code, click on the "Start" button to run your program. The output of the screen will appear like this.

C#

We can insert different values for Celsius and Fahrenheit. The output of the program will be like the below screen.

C#

This is how we create a C# program that will calculate both Celsius and Fahrenheit temperatures.
Ebook Download
View all
Learn
View all