Question: Write a C++ program to ask the user to give you the number of rows and number of columns, then make the multiplication table by using nested loop. For example, if the user enters 3 for rows and 4 for columns then the multiplication table would be like the following:
1 2 3 4
1 1 2 3 4
2 2 4 6 8
3 3 6 9 12
#include <iostream> #include <iomanip> using namespace std; int main() { int rows, columns; cout << "Enter number of rows: "; cin >> rows; cout << "Enter number of columns: "; cin >> columns; cout << " "; for (int i = 1; i <= columns; ++i) { cout << setw(4) << left << i; } cout << endl; for (int i = 1; i <= rows; ++i) { cout << setw(4) << left << i; for (int j = 1; j <= columns; ++j) { cout << setw(4) << left << i*j; } cout << endl; } return 0; }
Get Answers For Free
Most questions answered within 1 hours.