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 ?

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.

+ 1

excellent. thanks man. I need to obviously restudy multidimensional arrays because I forgot all about that.

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.

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);

0

What part are you stuck on?

0

sum += array[i, j];
multi *= sum;

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!!