89 107
Assignments Done
98.1%
Successfully Done
In July 2020

# Answer to Question #24425 in C++ for Tim

Question #24425
Write nested for loops and if-else statements if necessary that will display the following tables to the screen. The values should be calculated in the for loops, and not hard-coded. Use named consts for the dimensions of the table.

a. A square multiplication table where the user enters the largest integer to be multiplied

b.
0 0 0 4
0 0 3 4
0 2 3 4
1 2 3 4
1
2013-02-18T12:11:54-0500
#include <conio.h>
#include <iomanip>
#include <iostream>

using namespace std;

const int A_SIZE = 8;
const int B_SIZE = 5;

void table_a(int max_int)
{
/* Print row separating line */
cout << " quot;;
for (int n = 0; n <= A_SIZE * 5; n++)
cout << '-';
cout << endl;

/* Print table column headers */
cout << " & |";
for (int n = 1; n <= A_SIZE; n++)
cout << setw(3) << n << " |";
cout << endl;

/* Print row separating line */
for (int n = 0; n < 5 * A_SIZE + 5; n++)
cout << '-';
cout << endl;

for (int row = 1; row <= A_SIZE; row++)
{
cout << '|' << setw(3) << row << " |"; //print row header
for (char col = 1; col <= A_SIZE; col++)
cout << setw(3) << row * col << " |";
cout << endl;

/* Print row separating line */
for (int n = 0; n < 5 * A_SIZE + 5; n++)
cout << '-';
cout << endl;
}
}

void table_b()
{
for (int x = 1; x <= B_SIZE; x++)
{
for (int y = 1; y <= B_SIZE; y++)
if (x > B_SIZE - y)
cout << " " << y;
else
cout << " " << 0;
cout << endl;
}
}

int main()
{
table_a(4);
cout << endl;
table_b();

_getch();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!