+ 2
How to input a matrix using arrays?
c++ arrays
7 Answers
+ 5
Thank you Ekansh
Thank you Baptiste
+ 4
let's say that the matrix you want is :
int arr[4][3];
If you want to flatten it, you'll have this array :
int arr[4*3];
If i and j are proper indexes of the matrix, then the translation would be :
arr[i][j] - > arr[i * 4 + j]
+ 4
@Kirti
Try tapping the the checkmark,
next to the answer that helped you the most.
+ 2
You are welcomed :)
0
int matrix[n_columns][n_lines];
for (size_t i = 0; i < n_columns; ++i)
{
for (size_t j = 0; j < n_lines; ++j)
{cin >> matrix[i][j];}
}
- 1
Thank you Denis