Convertidor De Grados Celsius A Kelvin Y Fahrenheit En C#

En este ejercicio, crearemos un programa en C# que convierte un valor de temperatura de Celsius a Kelvin y Fahrenheit. El programa solicitará al usuario que introduzca la temperatura en grados Celsius, realizará los cálculos necesarios y mostrará los resultados.

Utilizaremos las siguientes fórmulas de conversión:

Kelvin = Celsius + 273

Fahrenheit = (Celsius × 18 / 10) + 32

Este ejercicio ayudará a reforzar el manejo de entradas, operaciones matemáticas y la salida formateada en C#.

Grupo

Introducción a C#

Objectivo

El objetivo de este ejercicio es desarrollar un programa en C# que convierta la temperatura de Celsius a Kelvin y Fahrenheit, demostrando las operaciones aritméticas y el manejo de la entrada de usuario en C#.

Cree un programa en C# para convertir de Celsius a Kelvin y Fahrenheit. Solicitará al usuario la cantidad de grados Celsius y utilizará las siguientes tablas de conversión:

Kelvin = Celsius + 273

Fahrenheit = Celsius × 18 / 10 + 32

Ejemplo de ejercicio en C#

 Copiar código C#
// First and Last Name: John Doe

using System;

namespace TemperatureConverter
{
    class Program
    {
        // The Main method is where program execution begins
        static void Main(string[] args)
        {
            // Declare a variable to store the Celsius temperature
            double celsius, kelvin, fahrenheit;

            // Prompt the user to enter a temperature in Celsius
            Console.Write("Enter temperature in Celsius: ");
            celsius = Convert.ToDouble(Console.ReadLine()); // Read user input and convert it to a double

            // Convert Celsius to Kelvin
            kelvin = celsius + 273;

            // Convert Celsius to Fahrenheit
            fahrenheit = (celsius * 18 / 10) + 32;

            // Display the results
            Console.WriteLine("\nTemperature Conversions:");
            Console.WriteLine("Kelvin: {0}", kelvin);
            Console.WriteLine("Fahrenheit: {0}", fahrenheit);

            // Wait for user input before closing the program
            Console.ReadKey(); // Keeps the console open until a key is pressed
        }
    }
}

 Output

Enter temperature in Celsius: 25

Temperature Conversions:
Kelvin: 298
Fahrenheit: 77

Comparte este ejercicio de C#