Headlines
Loading...
C program to read a matrix (m x n) column-wise, then transpose the matrix

C program to read a matrix (m x n) column-wise, then transpose the matrix

#include<stdio.h>

#include<conio.h>

void main() 

{

            int a[3][3],b[3][3],i,j;

            clrscr();

            printf("\nEnter the matrix:\n");

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

            {

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

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

            }

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

            {

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

                        {

                                    b[j][i]=a[i][j];

                        }

            }

            printf("\nTranspose Matrix:\n");

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

            {

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

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

                        printf("\n");

            }

            getch();

}

 

/*Output

Enter the matrix:

12 23 34

45 56 67

78 89 90

 

Transpose Matrix:

12      45      78

23      56      89

34      67      90

*/


*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***