Monday, August 3, 2009

How 2 use two loops & while taking First Value of both matrix at same time then increase the loop for second?

I am assuming the question means to use two loops and get the first value of both matrix (2 matrices), and how to increase the loop to get the second value.





I will also assume the matrices are the same size, as in 2 rows by 4 columns, and is held in an double array. That is, 2 high, 4 wide. I chose these numbers so you could see the difference of the hieght and width.





for (int i = 0; i %26lt; 2; i++) {


    for (int j = 0; j %26lt; 4; j++) {


        // The first time this loop happens, ints 'i' and 'j' will be at the position to get the first value out of the matrices.


        //valueOfMartix1 = matrix1[i][j];


        //valueOfMatrix2 = matrix2[i][j];


    }


}





How this works.


Loop no 1, with int i, loops twice. The values of i will be 0 and 1.


Everytime loop no 1. loops, loop no 2 starts.





Loop no 2, with int j, loops 4 times. The values of j are 0, 1, 2, and 3.


Everytime loop no 2. loops, you can use i and j to get the value of the matrix.





What you must do.


You need to determine what you need to do with the first value of the matrix. You place this code where I have the comments '//valueOfMartix1 = matrix1[i][j];', etc in loop no 2.



flower

No comments:

Post a Comment