``````void transpose_matrices(int a[],int result[])
{
int i,j,temp;

for (i = 0; i < 2; i++)
{
for (j = i+1; j < 2; j++)
{
temp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = temp;
}
}

}``````

it would be very helpful if someone guide with this transpose function.
i have done the above code. pls correct me.

first, that function needs to know the size of each matrix -- don't leave any dimensions unspecified as you did. Your function appears to be derived from the bubble sort -- toss it in the bit bin because it will not work. A transpose function does not need a temp variable nor does it swap variables. You need two matrixes where the number of rows and columns in the result matrix are the opposite of the number in the original source matrix. Thus, you can't leave any of the dimensions unspecified.

If you are unsure exactly what transpore is, read this tutorial. After you understand that, it should be fairly simple to write the program.

``````Given the matrix array:

char matrix[] = { 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l' };
Transpose means the rows becoming colums and the colums becoming rows.
Calling the first element of the first dimesion subscrit will produce
the first transpose row:

matrix    'a'
matrix    'e'
matrix    'i'

Calling the second element will give us:

matrix    'b'
matrix    'f'
matrix    'j'

The third element of each dimesion is:

matrix    'c'
matrix    'g'
matrix    'k'

And finally the last one:

matrix    'd'
matrix    'h'
matrix    'l'

All this can be accomplished by the use of two for loops

for (colum = 0; colum < reach end colum; colum++)
{
for (row = 0; row < reach end row; row++)
{
printf ("%c ", matrix[row][colum]);
}
putchar ('\n');
}``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.