calculations

C#:Convert from Celsius to Fahrenheit

C#: Convert from Celsius to Fahrenheit

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.

Code to Celsius into Fahrenheit

Convert Celsius into Fahrenheit -#1

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

 

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

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

 

Convert Celsius into Fahrenheit -Using function-#3

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

 

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

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

 

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.