If you'd like another nested loop problem, perhaps try this one:
Let's say we have a square matrix M of dimension 3.
[2][1][3]
[6][1][4]
[7][2][1]
The values of each element in the array are arbitrary.
Task: Write a function that will...
* take a pointer parameter m of type int, where m points to a 2D integer array (which represents our square matrix like M)
* calculate the transpose of m (hint: can be done with nested loops)
* persist the result in the location pointed to by m (that is, after the function is finished executing, m will point to the transposed matrix, not the original matrix)
thanks..but the thing is..I have not covered functions and array yet..just about too...will get back to this question..once i am ok with array and function.
I think I am fine with 2 level of nested loop for now...
can someone guide me on how to do..3 level of nested loops
I have got this exercise..that I saw in a book, can someone just describe the logic
1 2 3 4 5 6 7 8 9 10 11 12 13 14
1 for ( int i = 1; i <= 5; i++ )
2 {
3 for ( int j = 1; j <= 3; j++ )
4 {
5 for ( int k = 1; k <= 4 ; k++ )
6 cout << '*';
7
8 cout << endl;
9 } // end inner for
10
11 cout << endl;
12 } // end outer for
I know how the last loop, k works..I know it should print ****..but how does it loop to the outer loop, whichone goes first