Monday, September 12, 2011

transpose of the given matrix

transpose of the given matrix

#include<stdio.h>
#include<conio.h>
main()
{

    int a[5][5],b[5][5],m,n,i,j;
    clrscr();
    printf("\n enter the no. of rows of the matrix:");
    scanf("%d",&m);
    printf("\n enter the no. of columns of the matrix:");
    scanf("%d",&n);
    for(i=0;i<m;i++)
        for(j=0;j<n;j++)
        {
        printf("\n enter the  a[%d][%d]  element:",i+1,j+1);
        scanf("%d",&a[i][j]);
        }
            /* printing the given series */
    clrscr();
    printf("\n The given matrix is of order %d*%d",m,n);
    printf("\n The elements of the given matrix are:");
    for(i=0;i<m;i++)
    {
    printf("\n");
        for(j=0;j<n;j++)
        printf("\t %d",a[i][j]);
    }
    for(i=0;i<m;i++)     /* logic for transposing the matrix */
        for(j=0;j<n;j++)
            b[j][i]=a[i][j];
             /* printing the transpose */
    printf("\n ");
    printf("\n The transpose of the matrix is of order %d*%d",n,m);
    printf("\n The elements of the transpose of the given matrix are:");
    for(i=0;i<n;i++)
    {
    printf("\n");
        for(j=0;j<m;j++)
        printf("\t %d",b[i][j]);
    }
    getch();

}

No comments:

Post a Comment

Popular 5 Posts Last 7 days