Question: Write a C program that will transpose a square matrix. For example, a 3 x 3 matrix, say A, contains the 9 numbers as follows:

Write a C program that will transpose a square matrix.

For example, a 3 x 3 matrix, say A, contains the 9 numbers as follows:

1 2 3

4 5 6

7 8 9

The transpose of this matrix is

1 4 7

2 5 8

3 6 0

Complete this code below :

#include void swap( int *a, int *b ) {

/* INSERT CODE HERE */

return ;

}

void transpose( int A[][3], int r, int c ) {

/* INSERT CODE HERE. */

return ;

}

int main( int argc, char *argv[] ) {

int A[3][3] = { { 1, 2, 3 }, { 4, 5, 6 } , {7, 8, 9} } ;

int i, j ;

transpose( A, 3 , 3 ) ; for ( i = 0 ; i < 3 ; i++ ) {

for ( j = 0 ; j < 3 ; j++ )

printf( "%4d", A[i][j] ) ;

printf( " " ) ;

}

return 0 ;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!