Basic Programming C# Examples

C# Program to convert from Celsius degrees to Kelvin and Fahrenheit

The Program in C# Program to convert from Celsius degrees to Kelvin and Fahrenheit are given below:

using System;

namespace CelsiusConverter
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Codeauri Family, Enter the temperature in Celsius to convert them into Kelvin and Fahrenheit below : ");
            Console.WriteLine("Well,enter the temperature in Celsius: ");
            double celsius = Convert.ToDouble(Console.ReadLine());

            double kelvin = celsius + 273.15;
            double fahrenheit = celsius * 9 / 5 + 32;

            Console.WriteLine("Okay, the temperature in Kelvin is: " + kelvin);
            Console.WriteLine("Okay, the temperature in Fahrenheit is: " + fahrenheit);
            Console.ReadLine();
        }
    }
}

Output:

Hello Codeauri Family, Enter the temperature in Celsius to convert them into Kelvin and Fahrenheit below :
Well,enter the temperature in Celsius:
99
Okay, the temperature in Kelvin is: 372.15
Okay, the temperature in Fahrenheit is: 210.2

Pro-Tips💡

Here are the step by step execution of above program:

  1. using System; is a directive that imports the System namespace, which contains various classes and methods used in the program.
  2. namespace CelsiusConverter defines a namespace that contains all the classes and methods within it.
  3. class Program defines a class that contains the program’s logic.
  4. static void Main(string[] args) is the program’s entry point, which is executed when the program starts.
  5. Console.WriteLine("Hello Codeauri Family, Enter the temperature in Celsius to convert them into Kelvin and Fahrenheit below : "); prints a greeting message.
  6. Console.WriteLine("Well,enter the temperature in Celsius: "); prints a prompt asking the user to enter the temperature in Celsius.
  7. double celsius = Convert.ToDouble(Console.ReadLine()); reads the user’s input, converts it from a string to a double using Convert.ToDouble, and stores the result in the variable celsius.
  8. double kelvin = celsius + 273.15; calculates the temperature in Kelvin by adding 273.15 to the temperature in Celsius.
  9. double fahrenheit = celsius * 9 / 5 + 32; calculates the temperature in Fahrenheit using the formula (celsius * 9 / 5) + 32.
  10. Console.WriteLine("Okay, the temperature in Kelvin is: " + kelvin); and Console.WriteLine("Okay, the temperature in Fahrenheit is: " + fahrenheit); print the temperature in Kelvin and Fahrenheit, respectively.
  11. Console.ReadLine(); waits for the user to press the Enter key before ending the program.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X