In this tutorial you will learn about the C++ Program to Generate Multiplication Table and its application with practical example.
C++ Program to Generate Multiplication Table
In this tutorial, we will learn to create a C++ program that will Generate a Multiplication Table in C++ programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C++ programming topics:
- Operators in C++ Programming.
- Basic Input and Output function in C++ Programming.
- Basic C++ Programming.
Programfor generating the table:-
As we all know the integer, float, or double value in c++ programming. In c++ programming, we can take the input from the user in numbers format. In today’s program, we will take input in number format. Secondly, we will generate a Multiplication Table with the help of a small program. The numbers are the most useful terminology in any programing language. For number/arithmetic manipulation in c++ programming, there are many predefined functions available.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the variables required for the program. 2. Taking the input number from the user in number format for the generation of the table. 3. Send that variable to the for loop so that we can fing the table. 4. Generating the table and storing it in a variable. 5. Printing the table of the taken input number from the user. |
Program:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* C++ Program to Generate Multiplication Table */ #include <iostream> using namespace std; int main() { //declaring the variables for the program int n; //taking input number from the user cout << "Enter a positive integer: "; cin >> n; //no will store the integer value of the input number //calculating and printing the table for the reqiured number for (int i = 1; i <= 10; ++i) { //Printing the output for the program. cout << no << " * " << i << " = " << n * i << endl; } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- n = it will hold the input number value from the user.
- i = it will hold the integer value.
Taking Input numbers from the user.
Calculating the table of given numbers and Printing the output.