Arrays

so I am making a multiplication table using 2d arrays but it wont show correctly could some one guide me right please.

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
#include <iostream>
#include<iomanip>
using namespace std;





int main() 

{
	

int c[10][10];


for(int i = 1; i < 10;i++)
{
	for(int d = 1;d < 10;d++)
	{

		c[i][d]=i*d;

		cout<<setw(8)<<c[i][d];
        
		
	}
}
hope it helps:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include<iomanip>
using namespace std;

int main() 

{
	int c[10][10];
	for(int i = 1; i < 10;i++)
	{
		cout<<endl;
		for(int d = 1;d < 10;d++)
			cout<<setw(4)<<i*d<<" ";
	}
}
ahhhh thank you, i added just the cout<<end; after the first loop and it works perfectly, can you tell me why tho? like why i needed that there
well look at this code:

1
2
3
4
for(int i = 1; i < 10;i++)
{
	for(int d = 1;d < 10;d++)
	{


your main loop here is the d, it runs on collums, so it will print you 1 through 9, and 'i' stays on the first line. when you reached 9 on 'd', the i will ++, and go to the second line, but it didn't go there because you didn't write that command.
ahhhhh i c, man thank you very much
Topic archived. No new replies allowed.