Arrays?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Arrays??

in the challenges I have trouble with the speed but with a little more time I can usually get the answer. Except these two questions below. int[,]arr={{1,2},{4,5},{7,8}}; Console.Write(arr[2,1]); equals=8 how do I know to multiply 4*2 ?

21st Apr 2018, 11:46 PM
Bobby Angel
Bobby Angel - avatar
7 Answers
0
The value at array[i, j] (i=array j=element) gets added on to sum variable. The sum gets multiplied onto multi variable. sum += array[i, j]; is equivalent to sum = sum + array[i, j]; same with multi but obviously multiplying.
22nd Apr 2018, 12:44 AM
TurtleShell
TurtleShell - avatar
+ 1
excellent. thanks man. I need to obviously restudy multidimensional arrays because I forgot all about that.
22nd Apr 2018, 12:14 AM
Bobby Angel
Bobby Angel - avatar
0
The program doesnt multiply 4 by 2. arr[2, 1] is finding the array of index 2 (3rd one: {7, 8}) and then the element inside that array that is index of 1 (2nd one) then it prints out that element which is 8.
21st Apr 2018, 11:53 PM
TurtleShell
TurtleShell - avatar
0
this is the other one I'm stuck on... int[,] array = new int[2,2] {{1,1}, {2,1} }; int multi = 1 for(int i = 0; i < 2; ++i){ int sum = 0; for(int j = 0; j < 2; ++j){ sum += array[i , j]; } multi *= sum; } Console.Write(multi);
22nd Apr 2018, 12:26 AM
Bobby Angel
Bobby Angel - avatar
0
What part are you stuck on?
22nd Apr 2018, 12:28 AM
TurtleShell
TurtleShell - avatar
0
sum += array[i, j]; multi *= sum;
22nd Apr 2018, 12:42 AM
Bobby Angel
Bobby Angel - avatar
0
man that's so simple but it just wasn't clear to me. your excellent at quickly and concisely explaining it. thanks for the help!!
22nd Apr 2018, 12:47 AM
Bobby Angel
Bobby Angel - avatar