C Program to find the transpose of a matrix and check for symmetric

 #include<stdio.h>

main()

{

int a[10][10],b[10][10],i,j,m,n,flag=1;

clrscr();

printf("\nEnter the dimension of the matrix\n");

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

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

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

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

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

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

{

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

{

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

}

}

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

{

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

{

if(a[i][j]!=b[i][j])

flag=0;

}

}

printf("\nOriginal matrix\n");

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

{

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

{

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

}

printf("\n");

}

printf("\nTransposed Matrix\n");

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

{

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

{

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

}

printf("\n");

}

if(flag==1)

printf("\nSymmetric MAtrix");

else

printf("\nNot a Symmetric Matrix\n");

getch();

}















Output:


  1. Enter the dimension of the matrix

2

2


Enter the elements of the matrix

3

5

7

9


Original matrix

3       5

7       9


Transposed Matrix

3       7

5       9


Not a Symmetric Matrix



  1.   Enter the dimension of the matrix

    3

             3


             Enter the elements of the matrix

             1

             8

3

8

4

5

3

5

7


Original matrix

1       8       3

8       4       5

3       5       7


Transposed Matrix

1       8       3

8       4       5

3       5       7


Symmetric Matrix






Post a Comment

Previous Post Next Post