Grupo
Introducción a C++
Ojetivo
1. Declare una variable para almacenar la temperatura en grados Celsius.
2. Solicite al usuario que introduzca la temperatura en grados Celsius.
3. Use la fórmula de conversión Fahrenheit = (Celsius * 9/5) + 32.
4. Almacene el resultado en una segunda variable.
5. Muestre el resultado en grados Fahrenheit con `cout`.
Convierta grados Celsius a Fahrenheit.
Ejemplo de Código C++
Mostrar Código C++
#include <iostream> // Include the iostream library to handle input and output operations
using namespace std; // Use the standard namespace to avoid prefixing std::
// Main function - entry point of the program
int main() {
double celsius, fahrenheit; // Declare variables to store Celsius and Fahrenheit values
// Ask the user to enter temperature in Celsius
cout << "Enter temperature in Celsius: ";
cin >> celsius; // Read the Celsius value from user input
// Apply the formula to convert Celsius to Fahrenheit
fahrenheit = (celsius * 9 / 5) + 32;
// Display the result in Fahrenheit
cout << "Temperature in Fahrenheit: " << fahrenheit << endl;
return 0; // Return 0 to indicate successful program execution
}
Salida
Enter temperature in Celsius: 25
Temperature in Fahrenheit: 77
Comparte este ejercicio C++