- C# Tutorial
- C# Tutorial
- C# Basic Syntax
- C# Operators
- C# if else
- C# switch
- C# Loops
- C# break Vs. continue
- C# Arrays
- C# Strings
- C# Methods
- C# Examples
- C# Add Two Numbers
- C# Swap Two Numbers
- C# Reverse a Number
- C# Reverse a String
- C# Celsius to Fahrenheit
- Computer Programming
- Learn Python
- Python Keywords
- Python Built-in Functions
- Python Examples
- Learn C++
- C++ Examples
- Learn C
- C Examples
- Learn Java
- Java Examples
- Learn Objective-C
- Web Development
- Learn HTML
- Learn CSS
- Learn JavaScript
- JavaScript Examples
- Learn SQL
- Learn PHP
C# program to convert celsius to fahrenheit
This post is published to provide the tutorial that shows how we can use a C# program to convert temperature from celsius to fahrenheit.
Simple C# code to convert celsius to fahrenheit
Let me create a simple C# program that converts Celsius to Fahrenheit. But before writing the code, let me tell you the formula that is used to convert celsius to fahrenheit.
F = (C * 1.8) + 32
In this formula, F indicates Fahrenheit, whereas C indicates Celsius. Now let's create the program to implement this formula.
float c = 37; float f = (float) (c * 1.8) + 32; Console.WriteLine(f);
The output should exactly be:
98.6
In the above example, the (float) before (c * 1.8) is used to do typecasting. I have already discussed this topic. You can also use the double type, which I am going to use in an upcoming example.
C# code to convert celsius entered by the user to fahrenheit
Now let me create another example that does the same job as the previous example. The only difference is that this program allows the user to enter the value of Celsius at run-time of the program.
double celsius, fahrenheit; Console.WriteLine("Enter the Value of Celsius: "); celsius = Convert.ToDouble(Console.ReadLine()); fahrenheit = (celsius * 1.8) + 32; Console.WriteLine("\nEquivalent Temperature in Fahrenheit = " + fahrenheit);
Now the sample run with user input of 23 as temperature in celsius is shown in the snapshot given below.
« Previous Program jobails.com »