C++ Online Compiler
Example: Multiplication Table using For Loop in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Multiplication Table using For Loop #include <iostream> using namespace std; int main() { // Step 1: Declare a variable to store the number int number; // Step 2: Prompt the user to enter a number cout << "Enter an integer to display its multiplication table: "; // Step 3: Read the number from the user cin >> number; // Step 4: Display a header for clarity cout << "\nMultiplication table for " << number << ":\n"; // Step 5: Use a for loop to calculate and print the table // The loop iterates from 1 to 10 (inclusive) for (int i = 1; i <= 10; ++i) { // In each iteration, calculate the product // and print the result in the format: number x i = product cout << number << " x " << i << " = " << (number * i) << endl; } return 0; }
Output
Clear
ADVERTISEMENTS