Objective:
Write a C++ program to display the multiplication table of a number using a for loop.
Task:
- Write a program that prompts the user to enter a number.
- The program should display the multiplication table for that number from 1 to 10.
Code:
#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
cout << "Multiplication table of " << num << " is: " << endl;
for (int i = 1; i <= 10; i++) {
cout << num << " * " << i << " = " << num * i << endl;
}
return 0;
}Explanation:
This program prompts the user to enter a number (num).
It uses a for loop to display the multiplication table for that number, multiplying it with values from 1 to 10.
The result is displayed using the cout statement.
Expected Output:
Enter a number: 5
Multiplication table of 5 is:
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50