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:
using System;
is a directive that imports theSystem
namespace, which contains various classes and methods used in the program.namespace CelsiusConverter
defines a namespace that contains all the classes and methods within it.class Program
defines a class that contains the program’s logic.static void Main(string[] args)
is the program’s entry point, which is executed when the program starts.Console.WriteLine("Hello Codeauri Family, Enter the temperature in Celsius to convert them into Kelvin and Fahrenheit below : ");
prints a greeting message.Console.WriteLine("Well,enter the temperature in Celsius: ");
prints a prompt asking the user to enter the temperature in Celsius.double celsius = Convert.ToDouble(Console.ReadLine());
reads the user’s input, converts it from a string to a double usingConvert.ToDouble
, and stores the result in the variablecelsius
.double kelvin = celsius + 273.15;
calculates the temperature in Kelvin by adding 273.15 to the temperature in Celsius.double fahrenheit = celsius * 9 / 5 + 32;
calculates the temperature in Fahrenheit using the formula(celsius * 9 / 5) + 32
.Console.WriteLine("Okay, the temperature in Kelvin is: " + kelvin);
andConsole.WriteLine("Okay, the temperature in Fahrenheit is: " + fahrenheit);
print the temperature in Kelvin and Fahrenheit, respectively.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.