0% found this document useful (0 votes)
11 views1 page

Nested Loops HW

The document contains a C++ program that generates a multiplication table based on user-defined rows and columns. It prompts the user for the number of rows and columns, then displays the multiplication results in a formatted table. The program utilizes standard input/output libraries and formatting functions for alignment.

Uploaded by

qt cozy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Nested Loops HW

The document contains a C++ program that generates a multiplication table based on user-defined rows and columns. It prompts the user for the number of rows and columns, then displays the multiplication results in a formatted table. The program utilizes standard input/output libraries and formatting functions for alignment.

Uploaded by

qt cozy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Source Code:

// Multiplication Table
// Author: Yanni Nietcho
// Date: October 27, 2024

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
// Variables for # rows and columns
int rows, columns;

// Ask the user for input


cout<<"Multiplication Table Tool\n";
cout<<"How many rows would you like? ";
cin>>rows;
cout<<"How many columns would you like? ";
cin>>columns;

// Print column headers


cout << setw(4) << " ";
for (int col = 1; col <= columns; ++col) {
cout << setw(4) << col;
}
cout << endl;

// Print rows with row numbers and multiplication results


for (int row = 1; row <= rows; ++row) {
cout<<setw(2) << row << "| ";
for (int col = 1; col <= columns; ++col) {
cout<< setw(4) << row * col;
}
cout<<endl;
}

return 0;

Output:PS C:\Users\N.W.C.L LLC\Desktop> cd "c:\Users\N.W.C.L LLC\Desktop\" ; if


($?) { g++ [Link] -o NestedLoopsHw } ; if ($?) { .\NestedLoopsHw }

Multiplication Table Tool


How many rows would you like? 5
How many columns would you like? 6
1 2 3 4 5 6
1| 1 2 3 4 5 6
2| 2 4 6 8 10 12
3| 3 6 9 12 15 18
4| 4 8 12 16 20 24
5| 5 10 15 20 25 30
PS C:\Users\N.W.C.L LLC\Desktop>

You might also like