Can someone explain to me the algorithm for solving this quiz in C#?๐Ÿค”๐Ÿ˜€ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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
๐Ÿ…ข๐Ÿ…—๐Ÿ…๐Ÿ…ก๐Ÿ…ž๐Ÿ…•๐Ÿ‡บ๐Ÿ‡ฟ
๐Ÿ…ข๐Ÿ…—๐Ÿ…๐Ÿ…ก๐Ÿ…ž๐Ÿ…•๐Ÿ‡บ๐Ÿ‡ฟ - avatar
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
๐Ÿ…ข๐Ÿ…—๐Ÿ…๐Ÿ…ก๐Ÿ…ž๐Ÿ…•๐Ÿ‡บ๐Ÿ‡ฟ
๐Ÿ…ข๐Ÿ…—๐Ÿ…๐Ÿ…ก๐Ÿ…ž๐Ÿ…•๐Ÿ‡บ๐Ÿ‡ฟ - avatar
+ 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