Grupo
Introducción a C++
Ojetivo
1. Declara una variable para almacenar el radio del círculo.
2. Usa una constante para representar el valor de π (pi).
3. Pide al usuario que introduzca el radio.
4. Usa la fórmula área = π * radio * radio para calcular el área.
5. Muestra el área calculada con `cout`.
Calcula el área de un círculo (π * radio^2).
Ejemplo de Código C++
Mostrar Código C++
#include <iostream> // Include the iostream library for input and output
using namespace std; // Use the standard namespace
// Main function - entry point of the program
int main() {
const double PI = 3.14159; // Define a constant for the value of pi
double radius, area; // Declare variables for the radius and the area of the circle
// Ask the user to enter the radius of the circle
cout << "Enter the radius of the circle: ";
cin >> radius; // Read the radius from user input
// Calculate the area using the formula: area = π * radius^2
area = PI * radius * radius;
// Display the calculated area
cout << "The area of the circle is: " << area << endl;
return 0; // Return 0 to indicate successful execution
}
Salida
Enter the radius of the circle: 3
The area of the circle is: 28.2743
Comparte este ejercicio C++