2D multiplication table

Hi so I'm asked to make a multiplication table with a 2D array and then I have to make it to where the user would input the 2 numbers they would like to multiply from 0-9.So I was thinking of doing it like this and then its required for me to include the setw() to format it. After they enter there numbers and example would look like this.


Multiplication of 3 x 5


1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
.
.
1 * 5 = 5

2 * 1 = 2
2 * 2 = 4
.
.

2 * 5 = 10
.
.
.
3 * 1 = 3
3 * 2 = 6
.
.
3 * 5 = 15


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 #include <iostream>
#include <iomanip>
using namespace std;
int table(int i,int j)
{
	cout << "please enter a number from 0-9 then press enter";
	cin >> i;
	cout << "enter second number from 0-9";
	cin >> j;
	return i, j;
}
int main()
{
	int table[10][10];

	for (int i = 0; i <= 9; i++)
	{
		for (int j = 0; j <= 9; j++)
		{
			table[i][j] = i * j;
		}
	}
	{
		for (int i = 0; i <= 9; i++)
		{
			for (int j = 0; j <= 9; j++)
			{
				table[i][j] << '\n';
			}
		}
		return 0;
	}
}
Problem #1
 
return i, j;


problem #2

table[10][10] has 10 rows and 10 columns but no initial value
so what do you suggest?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream>
using namespace std;
int main()
{
	int t[10][10];
	int a,b;
	cout<<"Enter 1st number from 0 to 9:";
	cin>>a;
	cout<<"Enter 2nd number from 0 to 9:";
	cin>>b;
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			t[i][j]=i*j;
		}
	}
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			cout<<i<<"*"<<j<<"="<<t[i][j]<<endl;
		}
	}
}

OR
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
using namespace std;
int main()
{
	int t[10][10];
	int a,b;
	cout<<"Enter 1st number from 0 to 9:";
	cin>>a;
	cout<<"Enter 2nd number from 0 to 9:";
	cin>>b;
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			t[i][j]=i*j;
			cout<<i<<"*"<<j<<"="<<t[i][j]<<endl;
		}
	}
	
}
Thank you very much!
Topic archived. No new replies allowed.