+ 44

Can someone explain to me the algorithm for solving this quiz in C#?🤔😀

var size = 10; var matrix = new int[size, size]; for (int row = 0; row < size; row++) { for (int col = 0; col < row; col++) { matrix [row, col] = 1; } } Console.Write(matrix[3, 7]); Output: 0.

28th May 2019, 3:05 PM
🅢🅗🅐🅡🅞🅕🇺🇿
6 Answers
+ 18
It's because when the row is 3, the column can't be more than 2 (because the limit of the col is row). So when the element at index 3 and 7 is not set by default is 0. Hope it helps you 😉
28th May 2019, 3:23 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 20
Thanks TheWh¡teCat for the answer😀👍👍
28th May 2019, 3:36 PM
🅢🅗🅐🅡🅞🅕🇺🇿
+ 8
You are welcome, Sharof Gafurov🇺🇿 😉👍
28th May 2019, 3:55 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 7
I was confused trying to evaluate it inside my brain. Its seems like output should be 1 until you realise that nested loop is col < row. Tricky challenge 😉👍
2nd Dec 2019, 10:00 PM
Lev Tolstoy SPB
Lev Tolstoy SPB - avatar
+ 2
If output matrix[10 , 10] 0 1 2 3 4 5 6 7 8 9 10 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 2 1 1 0 0 0 0 0 0 0 0 0 3 1 1 1 0 0 0 0 0 0 0 0 4 1 1 1 1 0 0 0 0 0 0 0 5 1 1 1 1 1 0 0 0 0 0 0 6 1 1 1 1 1 1 0 0 0 0 0 7 1 1 1 1 1 1 1 0 0 0 0 8 1 1 1 1 1 1 1 1 0 0 0 9 1 1 1 1 1 1 1 1 1 0 0 10 1 1 1 1 1 1 1 1 1 1 0 matrix[3 , 7] = 0; 😁😁😁😁😁😁😁😁😁😁
25th Nov 2020, 9:27 AM
Oybek Salokhiddinov
Oybek Salokhiddinov - avatar
- 2
Example of Ruby
5th Jun 2021, 11:25 PM
حسين شكر فتحي المولى
حسين شكر فتحي المولى - avatar