Objective
Write a C# program to convert Celsius degrees to Kelvin and Fahrenheit. The program will prompt the user to input the temperature in Celsius degrees, and then use the following conversion formulas:
Kelvin = Celsius + 273
Fahrenheit = Celsius x 1.8 + 32
The program will then display the equivalent temperature in both Kelvin and Fahrenheit units.
Write Your C# Exercise
C# Exercise Example
using System; // Importing the System namespace to use Console functionalities
class Program
{
// Main method where the program execution begins
static void Main()
{
double celsius; // Declaring a variable to store the temperature in Celsius
double kelvin; // Declaring a variable to store the temperature in Kelvin
double fahrenheit; // Declaring a variable to store the temperature in Fahrenheit
// Asking the user to enter the temperature in Celsius and reading the input
Console.Write("Enter temperature in Celsius: ");
celsius = Convert.ToDouble(Console.ReadLine()); // Converting the input to a double
// Converting Celsius to Kelvin using the formula: Kelvin = Celsius + 273
kelvin = celsius + 273; // Performing the conversion to Kelvin
// Converting Celsius to Fahrenheit using the formula: Fahrenheit = Celsius * 1.8 + 32
fahrenheit = celsius * 1.8 + 32; // Performing the conversion to Fahrenheit
// Displaying the equivalent temperature in Kelvin
Console.WriteLine("Temperature in Kelvin: {0}", kelvin); // Printing the temperature in Kelvin
// Displaying the equivalent temperature in Fahrenheit
Console.WriteLine("Temperature in Fahrenheit: {0}", fahrenheit); // Printing the temperature in Fahrenheit
}
}