Generate Multiplication Table in C++

Codeblocks Visual Studio Code

Sure! Here's an example of a C++ program that generates a multiplication table for a given number:

#include <iostream>
using namespace std;

int main() {
    int num;

    // Get the number for which you want to generate the multiplication table
    cout << "Enter a number: ";
    cin >> num;

    // Generate the multiplication table
    cout << "Multiplication table for " << num << ":\n";
    for (int i = 1; i <= 10; i++) {
        cout << num << " x " << i << " = " << num * i << endl;
    }

    return 0;
}

The program prompts the user to enter a number.

It then uses a for loop to generate the multiplication table for that number. The loop iterates from 1 to 10.

Inside the loop, it calculates and prints the result of multiplying the input number with the loop variable i.

For example, if you enter 5, the program will generate the multiplication table for 5:

Multiplication table for 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

You can modify this program to generate multiplication tables for different numbers by changing the value of the num variable.

Comments
Loading...
Sorry! No comment found:(

There is no comment to show for this.

Leave your comment
Tested Versions
  • GCC 6.3.0