Ejercicio
Conversión
Objetivo
Cree un programa en C# para convertir de grados Celsius a Kelvin y Fahrenheit: le pedirá al usuario la cantidad de grados Celsius y utilizando las siguientes tablas de conversión:
Kelvin = Celsius + 273
Fahrenheit = Celsius x 18 / 10 + 32
Código de Ejemplo
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
}
}