I'm working on a function that takes a square matrix (2D array), rotates it in steps of 90 degrees, then prints all 4 rotations. What I've been working on is printing these rotations side by side, rather than directly underneath each other. This is what I'm able to produce, given the first matrix shown below:
123
123
123
111
222
333
321
321
321
333
222
111
What I'm looking to achieve:
123 111 321 333
123 222 321 222
123 333 321 111
Any help on how to approach it is really appreciated as I've hit a dead and can't get anything to work.
code:
//get transformation of matrix
for(num_rotations = 0;num_rotations < 3;num_rotations++){
for(row=0;row<num_rows;row++){
for(col=0;col<3;col++){
temp_arr[row][col] = working_arr[col][row];
}
}
}
Whilst inside the 1st 'for' loop, the 2nd and 3rd 'for' loops are then repeated, and the final line is replaced with:
working_arr[row][col] = temp_arr[row][3-col-1];//reverse columns for a single rotation
A print statement is placed at the end of the very first 'for' loop.