# C# program to convert a temperature from Celsius to Fahrenheit

Here, we are going to learn how to convert a temperature from Celsius to Fahrenheit in C#?
Submitted by Nidhi, on September 12, 2020

Here we will read the temperature in Celsius and then convert it into the corresponding Fahrenheit temperature.

Program:

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

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

using System;

class Program
{
static double convertToFahrenheit(double celTemp)
{
double fTemp = 0;

fTemp = (celTemp * 9) / 5 + 32;

return fTemp;
}
static void Main(string[] args)
{
double celTemp=0;
double ferTemp=0;

Console.Write("Enter the value of temperature in Celsius(°C): ");

ferTemp = convertToFahrenheit(celTemp);
Console.WriteLine("Fahrenheit temperature is(°F) : " + ferTemp);
}
}

Output:

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

Explanation:

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

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

What's New (MCQs)

Top Interview Coding Problems/Challenges!

IncludeHelp's Blogs

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates