C++ Online Compiler
Example: Multiplication Table Generator in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Multiplication Table Generator #include <iostream> using namespace std; int main() { // Step 1: Declare a variable to store the user's number int number; // Step 2: Prompt the user to enter a number cout << "Enter an integer to display its multiplication table: "; cin >> number; // Step 3: Print a header for the table cout << "\nMultiplication Table for " << number << ":" << endl; // Step 4: Use a for loop to calculate and print the table // The loop iterates from 1 to 10 for (int i = 1; i <= 10; ++i) { // Calculate the product int product = number * i; // Print the current line of the table in "number x i = product" format cout << number << " x " << i << " = " << product << endl; } return 0; }
Output
Clear
ADVERTISEMENTS