# Thread: c two dimensional array code

1. ## c two dimensional array code

I tried to understand C array from various sources and then looked into the codes below but I cannot understand it. Can you please tell me what the code exactly does and what they meant to write?

why they declared five variables matrix[3][3],i,j,r,c in the first place?

http://s2.postimage.org/p9rznkq2g/Tw...onal_array.gif

2. You made a screenshot of your code? How about actually just posting it here between code tags like a normal person?

Quzah.

3. Originally Posted by quzah
You made a screenshot of your code? How about actually just posting it here between code tags like a normal person?

Quzah.
Thank you friend. But in the source it was image. Anyway, I typed now in notepad and made copy paste here
Code:
```int main()
{
int matrix[3][3],i,j,r,c;
clrscr ();
printf ("Enter the order of matrix\n");
scanf("%d%d", &r, &c);
printf ("Enter elements of %d * %d matrix\n", r,c);
for (i=0; i<r; i++)
for (j=0; j<c; j++)
scanf ("%d", &matrix[i][j]);
printf ("Given matrix:\n");
for (i=0; i<r; i++)
{
for (j=0; j<c; j++)
printf ("%d\t", matrix[i][j]);
printf ("\n");
}
printf ("%d\t", matrid [2][2]);
getch ();
return 0;
}```

4. They have declared five variables to:

matrix[3][3] - declare a 3x3 array.
i - loop through matrix[ HERE ][ ]
j - loop through matrix[ ][ HERE ]
r - stop counter i
c - stop couner j

The problem here is that you never make sure r and c are less than 3.

Quzah.

5. You should really find a better source for learning C, than watching crappy animated GIF files generated by a TurboC programmer.
http://cboard.cprogramming.com/c-pro...low-codes.html