C++ Program to Generate Multiplication Table
To generate a multiplication table for a given number, you can use a for loop that iterates from 1 to 10 (or any other range you prefer) and prints the product of the given number and the loop variable.
Here’s how you can write a Turbo C++ program to generate a multiplication table for a given number:
#include <iostream.h>
#include <conio.h>
void main() {
clrscr(); // Clear the screen (specific to Turbo C++)
int n;
cout << "Enter the number for which you want to generate a multiplication table: ";
cin >> n;
// Generate multiplication table
for (int i = 1; i <= 10; ++i) {
cout << n << " x " << i << " = " << n * i << endl;
}
getch(); // Wait for user input (specific to Turbo C++)
}
To compile and run this program in Turbo C++:
- Open Turbo C++.
- Create a new file and copy-paste the above code into it.
- Save the file.
- Compile the code (usually by pressing Alt + F9).
- Run the program (usually by pressing Ctrl + F9).
The program will prompt you to enter a number for which you’d like to generate a multiplication table. It will then display the table, ranging from 1 to 10, in the format n x i = n*i.
