Multiplication Table In C++ - C++ Programming Tutorial
C++ Course / Miscellaneous / Multiplication Table In C++

Multiplication Table In C++

BLUF: Mastering Multiplication Table In C++ is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Multiplication Table In C++

C++ is renowned for its efficiency. Learn how Multiplication Table In C++ enables low-level control and high-performance computing in the tutorial below.

In this guide, we will explore various scenarios of multiplication table programs in C++.```

include<iostream>

using namespace std;

int main{

int number;

cout<< "Enter the number for printing multiplication table"<< endl;

cin >>number;

// printing the multiplication number

for(int i=1; i<11; i++){

cout<< number <<" X " << i <<" = "<< number*i <<endl;

}

return 0;

}

Example


### Case 1:

Receive a numerical input from the user, then display the multiplication table corresponding to the entered number.

C++ program:

include<iostream>

using namespace std;

int main{

int number;

cout<< "Enter the number for printing multiplication table"<< endl;

cin >>number;

// printing the multiplication number

for(int i=1; i<11; i++){

cout<< number <<" X " << i <<" = "<< number*i <<endl;

}

return 0;

}

Example


Output:

Explanation:

In the provided C++ code snippet, user input is solicited to specify the multiplication factor. Subsequently, a for loop is implemented to iterate over numbers ranging from one to ten. Within the output statements, the input number is multiplied by the iterating number, generating the multiplication table spanning from one to ten. This loop will conclude its iterations, allowing the main function to terminate with a return value of zero.

### Case 2:

Accept a numerical input from the user, then display the multiplication chart corresponding to that number without relying on the multiplication symbol.

C++ program:

include<iostream>

using namespace std;

int main{

int number;

cout<< "Enter the number for printing multiplication table"<< endl;

cin >>number;

// printing the multiplication number without using the multiplication operator

int sum =number;

for(int i=1; i<11; i++){

cout<< number <<" X " << i <<" = "<< sum <<endl;

sum = sum + number;

}

}

Example


Output:

Explanation:

In the given c++ code snippet, the program prompts the user to input a number, which will be used for multiplication. Subsequently, a for loop is employed to go through numbers from one to 10. Within the print statements, a variable called "sum" is defined and set to the initial value of the input number. During each iteration, the sum is incremented by the input number, and this updated sum is then printed. This process continues until the loop concludes, allowing the main function to exit gracefully by returning zero. This methodology illustrates the generation of a multiplication table for a specified number.

### Case 3:

Receive a numerical input from the user, then display the multiplication table within a specified range.

C++ program:

include<iostream>

using namespace std;

int main{

int number;

cout<< "Enter the number for printing multiplication table"<< endl;

cin >>number;

// multiplication in given range(start, end);

int start;

cout<< "Enter the first of the range" << endl;

cin>> start;

int end;

cout<< "Enter the end of the range" << endl;

cin>> end;

// printing the multiplication number within a range

for(int i=start; i<=end; i++){

cout<< number <<" X " << i <<" = "<< number*i <<endl;

}

}

Example


Output:

Explanation:

In the provided C++ code, user input is required to specify the number for multiplication. Additional inputs are also requested to determine the range, with one indicating the range's start and the other indicating its end. Subsequently, a for loop is implemented to cycle through numbers from one to ten. Within the print statements, each number is multiplied by the user input to generate the multiplication table spanning from one to ten. This process continues until the loop concludes, leading to the main function's termination with a return value of zero. This is the method employed to display the multiplication table for a given number.

### Case 4:

Receive a numerical input from the user, then display the multiplication chart for that specific number by utilizing recursion.

C++ program:

include <iostream>

using namespace std;

void printMultiplicationTable(int number, int current = 1) {

if (current > 10) {

return;

}

cout << number << " x " << current << " = " << (number * current) << endl;

printMultiplicationTable(number, current + 1);

}

int main {

int number;

cout << "Enter a number: ";

cin >> number;

cout << "Multiplication Table for " << number << "using recursion :\n";

printMultiplicationTable(number);

return 0;

}

Example


Output:

Explanation:

In the provided code, there exist two functions: the main function and the printMultiplicationTable function. The printMultiplicationTable function requires two arguments: number, which represents the value for generating the multiplication table, and current, which is utilized to monitor the current multiplier.

Within the function, the initial check will be if the current value is less than or equal to ten. In case the current value exceeds ten, the recursion process will halt. When the current value falls within the specified range, we will then calculate and display the product of the number and current value, illustrating the corresponding row in the multiplication table.

Subsequently, we initiate a recursive invocation to displayMultiplicationTable, increasing the current value by one. This recursive function persists until the "current" value surpasses ten, halting the recursion process as it reaches the base condition.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience