A transpose of a given matrix is a matrix obtained by changing elements of rows to colums and columns to rows

eg :

1 3 5 1

2 1 6 1

5 3 2 9

The transpose of above matix is

1 2 5

3 1 3

5 6 2

1 1 9

## write a C program to find transpose of a matrix using for loop

write a C program to find transpose of a matrix using for loop / WAP to find transpose of matrix

#include<stdio.h>

#include<conio.h>

int main()

{

int m, n, i, j;

int c[10][10], transpose[10][10]; // c[][] is original matrix

printf("To find for transpose of a given matrix ");

printf("Enter the number of rows and columns of matrix ");

scanf("%d%d",&m,&n);

printf("Enter the elements of matrix \n");

for( i = 0 ; i < m ; i++ )

{

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

{

scanf("%d",&c[i][j]);

}

} for( i = 0 ; i < m ; i++ )

{

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

{

transpose[j][i] = c [i][j];

}

}

printf("Transpose of matrix is:-\n");

for( i = 0 ; i < n ; i++ )

{

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

{

printf("%d\t",transpose[i][j]);

}

printf("\n");

}

getch();

return 0;

}

OUTPUT:

To find transpose of a given matrix

Enter the number of rows and columns of matrix 2 2

Enter the elements of matrix 0 2 3 4

Transpose of matrix is:

0 3

2 4

## WAP for transpose of a matrix using while loop

write a C program to print transpose of a matrix using while loop / write a C program for transpose of a matrix

#include<stdio.h>

#include<conio.h>

int main()

{

int m, n, i=0, j=0;

int c[10][10], transpose[10][10];

printf("To print transpose of a given matrix ");

printf("Enter no. of rows and columns of matrix ");

scanf("%d%d",&m,&n);

printf("Enter elements into matrix \n");

while(i<m)

{

while(j<n)

{

scanf("%d",&c[i][j]);

transpose[j][i] = c [i][j];

j++ ;

}

i++;

}

printf("Transpose of matrix is :\n");

i=0;

j=0;

while(i<m)

{

while(j<n)

{

printf("%d\t",transpose[i][j]);

j++ ;

}

printf("\n");

i++;

}

}

OUTPUT:

To print transpose of a given matrix

Enter no. of rows and columns of matrix 2 2

Enter elements into matrix 0 1 1 0

Transpose of matrix is:

0 1

1 0