+ 2

How to input a matrix using arrays?

c++ arrays

5th Sep 2017, 9:33 AM
Kirti
Kirti - avatar
7 Answers
5th Sep 2017, 9:35 AM
Ekansh
+ 5
Thank you Ekansh Thank you Baptiste
5th Sep 2017, 10:14 AM
Kirti
Kirti - avatar
+ 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]
5th Sep 2017, 9:47 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 4
@Kirti Try tapping the the checkmark, next to the answer that helped you the most.
5th Sep 2017, 11:30 AM
Manual
Manual - avatar
+ 2
You are welcomed :)
5th Sep 2017, 10:39 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
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];} }
5th Sep 2017, 10:02 PM
Denis Felipe
Denis Felipe - avatar
- 1
Thank you Denis
6th Sep 2017, 4:54 PM
Kirti
Kirti - avatar