Grupo
Introducción a C++
Ojetivo
1. Declarar una variable entera para almacenar el número ingresado por el usuario.
2. Solicitar al usuario que ingrese el número cuya tabla de multiplicación se generará.
3. Usar un bucle `for` para multiplicar el número del 1 al 10.
4. En cada iteración, mostrar el producto con formato.
5. Asegurarse de que la salida sea clara y legible para el usuario.
Imprimir la tabla de multiplicar de un número.
Ejemplo de Código C++
Mostrar Código C++
#include <iostream> // Include the iostream library for input and output operations
using namespace std; // Use the standard namespace to avoid using std:: prefix
// Main function - starting point of the program
int main() {
int number; // Declare an integer variable to store the user input
// Ask the user to enter a number for which the multiplication table will be generated
cout << "Enter a number to print its multiplication table: ";
cin >> number; // Read the input number from the user
// Use a for loop to print the multiplication table from 1 to 10
for (int i = 1; i <= 10; ++i) {
// Display the current step of the multiplication table
cout << number << " x " << i << " = " << number * i << endl;
}
return 0; // Return 0 to indicate the program ended successfully
}
Salida
Enter a number to print its multiplication table: 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
Comparte este ejercicio C++