In: Computer Science
4, Make the table project with C++. Write a function with the following interface: void multiplyTable(int num) This function should display the multiplication table for values from 1...num. For example, if the function is passed 10 when it is called, it should display the following: 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 90 10 20 30 40 50 60 70 80 90 100 As another example, if the function is passed 5, it would print the following: 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 Write a main() to test your function. Main should ask the user for an input value (in the range 1..15), then call multiplyTable with that value. Note: • The maximum parameter value that your function will need to handle is 15. • Make sure that your numbers are aligned properly as illustrated in the examples above.
#include <iostream>
#include <iomanip>
using namespace std;
void multiplyTable(int num)
{
// from 1 to num
for (int i = 1; i <= num; i++)
{
// create a row for every multiplication
for (int j = 1; j <= num; j++)
cout << setw(4) << i * j;
cout << endl;
}
}
int main()
{
// read an integer from 1 to 15
cout << "Enter integer from 1...15: ";
int num;
cin >> num;
multiplyTable(num);
return 0;
}
.
.