Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Function/method to convert Celsius into Fahrenheit -Entered by user

C#:Convert from Celsius to Fahrenheit

Posted on May 6, 2023May 6, 2023

Table of Contents

  • C#: Convert from Celsius to Fahrenheit
    • Code to Celsius into Fahrenheit
      • Convert Celsius into Fahrenheit -#1
      • Convert Celsius into Fahrenheit -Entered by the user-#2
      • Convert Celsius into Fahrenheit -Using function-#3
      • Convert Celsius into Fahrenheit Using the function-Entered by the user-#4

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

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes