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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started