Sunday 3 April 2011

transpose of a maticx


/*transpose of a maticx*/
#include<iostream.h>
#include<conio.h>
void main()
{
 int m=3,n=3; //row size, colum size is 3 , m=n
 int a[][3]={1,2,3,4,5,6,7,8,9};//initializing the array
 clrscr();
cout<<"after transpose"<<endl;
 for(int i=0;i<=m-1;i++)  //this loop for rows
  for(int j=i+1;j<=n-1;j++) //this loop for columns
  {
   a[i][j]=a[i][j]+a[j][i]-(a[j][i]=a[i][j]); //swap the elements above diagnols with those below diagnols
  }
//displaying the transpose of 'a' matrix
  for(i=0;i<=m-1;i++)
  {
   cout<<"\n"; //for displaying row wise
   for(j=0;j<=n-1;j++)
   {
    cout<<a[i][j]<<"\t";
   }
  }
  getch();
 }

No comments:

Post a Comment