Celsius into Fahrenheit
Table of Contents
In this article, we will discuss the concept of the C#: Convert from Celsius to Fahrenheit
In this post, we will learn how to write a program to Convert from Celsius into Fahrenheit and display the result on the screen. Here, we have four methods and explain how to calculate Fahrenheit using the given Celsius value and display the result on the screen in C# programming language.
In this program, the user declares two variables as Celsius and Fahrenheit, and initiates the value as 40.0 to variable- Celsius. The scientific equation will convert it from Celsius into Fahrenheit in the C# programming language.
Program 1
// C# program to convert Celsius to Fahrenheit
using System;
namespace temperature
{
public class CelstoFahr
{
public static void Main(string[] args)
{
double celsius,fahrenheit;
//Declare variables
celsius=40.00;
//initialize value to Celsius
fahrenheit=(1.8*celsius)+32;
//Caculate Fahrenheit
Console.WriteLine ("The temperature in Fahrenheit is: "+fahrenheit);
//Display the result
Console.ReadKey();
}
}
} When the above code is executed, it produces the following result
the temperature in Fahrenheit is: 104
In this program, the user declares two variables as Celsius and Fahrenheit. The program asks for input from the user to Celsius then the input will convert from Celsius into Fahrenheit in the C# programming language using the scientific equation.
Program 2
// C# program to convert Celsius to Fahrenheit
//Ask input from user
using System;
namespace temperature
{
public class CelstoFahre
{
public static void Main(string[] args)
{
double celsius,fahrenheit;
//Declare variables
Console.WriteLine ("Enter temperature in Celsius: ");
//Ask for input from the user
celsius=Convert.ToDouble(Console.ReadLine());
//Reading the input
fahrenheit=(1.8*celsius)+32;
//Caculate Fahrenheit
Console.WriteLine ("The temperature in Fahrenheit is: "+fahrenheit);
//Display the result
Console.ReadKey();
}
}
} When the above code is executed, it produces the following result
Enter temperature in Celsius: 36.9 The temperature in Fahrenheit is: 98.42
In this program, the user declares a double variable as a parameter for Celsius in the user-defined function. When the user runs the program (when calling the function), the value for Celsius passes as an argument to the function.
Finally, the Fahrenheit 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 TempCelsToFahre1
{
public static void Main(string[] args)
{
//Calling the function with an argument
double fahrenheit=celsiusToFahrenheit(37.00);
double fahrenheit1=celsiusToFahrenheit(100.00);
double fahrenheit2=celsiusToFahrenheit(00.00);
//Display the result on the screen
Console.WriteLine ("temperature in Fahrenheit: "+fahrenheit);
Console.WriteLine ("temperature in Fahrenheit: "+fahrenheit1);
Console.WriteLine ("temperature in Fahrenheit: "+fahrenheit2);
Console.ReadLine();
}
//function definition
private static double celsiusToFahrenheit(double celsius)
{
return ((celsius*9/5)+32);
}
}
} When the above code is executed, it produces the following result
The temperature in Fahrenheit: 98.6 The temperature in Fahrenheit: 212 The temperature in Fahrenheit: 32
In this program, the user declares a double variable as a parameter for Celsius in the user-defined function. When the user runs the program (when calling the function), The program asks for input from the user for Celsius and the value for Celsius passes as an argument to the function.
Finally, the Fahrenheit value is calculated and displayed on the screen using the scientific equation in the C# programming language..
Program 4
// C# program to convert Fahrenheit to Celsius
//using function
using System;
namespace Temperature
{
public class TempCelsToFahre
{
public static void Main(string[] args)
{
Console.WriteLine ("Enter temperature in Celsius: ");
//Ask for input from the user
double celsius=Convert.ToDouble(Console.ReadLine());
//Reading the input
double fahrenheit=celsiusToFahrenheit(celsius);
//Calling the function with an argument
Console.WriteLine ("temperature in Fahrenheit: "+fahrenheit);
//Display result on the screen
Console.ReadLine();
}
//function definition
private static double celsiusToFahrenheit(double celsius)
{
return ((celsius*9/5)+32);
}
}
} When the above code is executed, it produces the following result
Enter temperature in Celsius:
36.8
the temperature in Fahrenheit: 98.24
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
Celsius into Fahrenheit in the C# program
Fahrenheit into Celsius in C# program
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.