-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path32array2D.c
More file actions
28 lines (23 loc) · 872 Bytes
/
32array2D.c
File metadata and controls
28 lines (23 loc) · 872 Bytes
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
#include <stdio.h>
int main()
{
// Now, what if we don't know how many rows and columns are there?
// then we got to calculate them
int numbers[2][4 ] = {
{1, 2, 3},
{4, 5, 6}
};
int rows = sizeof(numbers)/sizeof(numbers[0]); // we are divding the total number of bytes in the 2D array with the number of bytes in one row
int columns = sizeof(numbers[0])/sizeof(numbers[0][0]); // it divides the size of bytes in one row with the size of byte of one element
printf("rows: %d\n", rows);
printf("columns: %d\n", columns);
for(int i = 0; i < rows; i++)
{
for(int j =0; j < columns; j++)
{
printf("%d ", numbers[i][j]);
}
printf("\n");
}
return 0;
}