More habitually, when the appeal to the elements of an array in cycles is carried out in rows and not in columns, as you have. That is, instead of
for (i = 0; i < n; i++) ^^^^^ { for (j = 0; j < m; j++) ^^^^^ { printf("arrayl (%d)(%d) = ", i, j); scanf_s("%d", arrayl); } }
It would be better to write
for (i = 0; i < m; i++) ^^^^^ { for (j = 0; j < n; j++) ^^^^^^ { printf("arrayl (%d)(%d) = ", i, j); scanf_s("%d", &arrayl[i * n + j] ); } }
because m is the number of rows, and n is the number of columns.
Otherwise this hint
printf("arrayl (%d)(%d) = ", i, j); ^^^^
in your original cycle does not look right and should be
printf("arrayl (%d)(%d) = ", j, i); ^^^^
It is this (corrected) cycle that I will keep in mind when answering a question, so as not to confuse the reader’s answer and question.
You can output the elements of an array with the following statement inside nested loops.
printf("%5d ", array1[i * n + j] );
And for input you need to use a pointer to the corresponding element
scanf_s("%d",&arrayl[ i * n + j] );
That is, in your program a two-dimensional array is simulated using a one-dimensional array.
If there is a two-dimensional array and its element indices i and j , as, for example,
array2[i][j]
then the sequence number of the element of this array will be equal to i * n + j . This will be the index of the one-dimensional array.
For simplicity, imagine that you have a two-dimensional array with 10 elements in a row. Then the sequence number of the element, for example, array2[2][5] will be 25. And you can think of the number 25 as 2 * 10 + 5 , that is, 2 * n + 5 , where n is the number of elements in the line. Keep in mind that indexes start from 0. This means that before any element that is located in the line with index 2, there are 2 lines of elements.