I'm tring to code an algorithm that given a square matrix of even dimension, transpone 2x2 submatrix in it

Example:

So, I written all the code (check below).

Problem is, I written it based on a matrix[ row ][ col ] logic, not with pointers , while the assignment requires that matrix dimension should be asked to the user.

Now, if write a function prototype like this

const int MAX_COLS = 100; void transpose ( int matrix[ ][MAX_COLS], const int ROWS, const int COLS );

compiler won't do it's job, and if I choose a pointer logic I should rewrite all this from 0 ( and it's far more complicated to write it with pointers, I think ).

It's a frequent issue for me, it's happened before and I choosed always to practice with pointers because i was at the beginning with them.

Now it's startng to get annoying, so

Is there an easy way to fix this or should i go for the torture?

Here is the code I think should do the job (not tested).

void transpose ( int matrix[][ COLS ], const int ROWS, const int COLS ) { int temp; for ( int current_row = 0; current_row < ROWS; current_row = current_row + 2 ) { for ( int current_col = current_row + 2; current_col < COLS; current_col = current_col + 2 ) { temp = matrix[ current_row ][ current_col ]; matrix[ current_row ][ current_col ] = matrix[ current_col ][ current_row ]; matrix[ current_col ][ current_row ] = temp; temp = matrix[ current_row ][ current_col + 1 ]; matrix[ current_row ][ current_col + 1] = matrix[ current_col ][ current_row + 1 ]; matrix[ current_col ][ current_row + 1 ] = temp; temp = matrix[ current_row + 1 ][ current_col ]; matrix[ current_row + 1 ][ current_col ] = matrix[ current_col + 1 ][ current_row ]; matrix[ current_col + 1 ][ current_row ] = temp; temp = matrix[ current_row + 1 ][ current_col + 1]; matrix[ current_row + 1 ][ current_col + 1 ] = matrix[ current_col + 1 ][ current_row + 1 ]; matrix[ current_col + 1 ][ current_row + 1] = temp; } } }

This post has been edited by **domenico**: 17 February 2013 - 08:57 AM