-
2D table problem
I have a 2D table problem. I want to fill 2D table with some numbers but I do not know how to do it.
Example:
int main()
{
int generate;
printf("Enter a number: ");
scanf("%d", &generate);
for (int i=0; i<10; i++)
{
for (int j=0; j<10; j++)
{
Table[i][j] = generate;
printf("%d,%d\n", Table[i][j]);
}
}
return 0;
}
With this code I only fill the the [i] part.
What Am I missing?
-
The first brace of the array is never refered to for data. It is the outer braces. That's because the first set of braces holds the index of the array of arrays-of-data. Like this:
A
R
R
A
Y
[0] - [0] [1] [2] [3] [4] [5] sub-array
[1] - [0] [1] [2] [3] [4] [5] sub-array
[2] - [0] [1] [2] [3] [4] [5] sub-array
[3] - [0] [1] [2] [3] [4] [5] sub-array
----------------------------------------------
So to access this array[3][5]<---you will get the data in this brace
Code:
int c = 21;
for(i = 0; i < 3; i++)
for(k = 0; k < 5; k++)
{
array[i][k] = c;
printf("[%i][%i]: %i \n"
"----------------\n", i, k, array[i][k]);
c++;
}