bob sinclair
bob sinclair

Reputation: 11

how to represent a 2d matrix using a 1D array in c

in a two dimensional matrix in c how do i know when the element is still on the current line and not on the second line of a matrix in a 1 dimensional array. aka how do i show that d is on the top line and d is one the next line in these two matrixs?

a b c
d e f

or

a b c d

e f g h

Upvotes: 1

Views: 1672

Answers (1)

Saša Ćetković
Saša Ćetković

Reputation: 905

You can represent it in a 1D array, but you have to take care of the logic, which index belongs to which row and column.

e.g.: for a 4×4 matrix - index 0 to 3 would be on the first row. 4-7 on the second, etc.

Upvotes: 1

Related Questions