Thursday, 12 January 2012

Write a c program to Transpose a given matrix

#include<stdio.h>
#include<conio.h>

void main()
{
int n,i,j,temp,a[5][5];
clrscr();
printf("Enter the order of the matrix::\n");
scanf("%d",&n);
printf("Enter the elements of the matrix::\n");
for(i=0;i<n;i++)
{
    for(j=0;j<n;j++)
    {
        scanf("%d",&a[i][j]);
    }
}
for(i=0;i<n;i++)
{
    for(j=i+1;j<n;j++)
    {
        temp=a[i][j];
        a[i][j]=a[j][i];
        a[j][i]=temp;
    }
}
printf("Transpose Matrix is::\n");
for(i=0;i<n;i++)
{
    for(j=0;j<n;j++)
    {
        printf("%d ",a[i][j]);
    }
    printf("\n");
}
getch();
}

No comments:

Post a Comment