Computer Scientists are Pretty Pessimistic

Sunday 25 October 2015

WAP to transpose a square matrix.


What is transpose matrix ?
Find it here : Transpose Matrix Defination

Code ::

#include <stdio.h>
int main ()
{
    int matrix[100][100],trans[100][100],row,col,i,j;
    printf("Enter rows and columns size of matrix: ");
    scanf("%d %d",&row,&col);
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            scanf("%d",&matrix[i][j]);
        }
    }

    printf("\nMain Matrix is:\n");
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            printf("%d ",matrix[i][j]);
        }
        printf("\n");
    }
    for(i=0;i<row;i++)
    {
        for(j=0;j<col;j++)
        {
            trans[j][i]=matrix[i][j];
        }
    }
    printf("\nTranspose matrix is:\n");
    for(i=0;i<col;i++)
    {
        for(j=0;j<row;j++)
        {
            printf("%d ",trans[i][j]);
        }
        printf("\n");
    }
    return 0;
}

No comments:

Post a Comment