Selasa, 14 Juni 2011

Matrix Tranpose

Matrix tranpose understanding is obtained from the moving elements of the row elements become columns and vice versa, moving the elements into elements of a column in the row.
The following is the sourcecode:

#include <iostream.h>
#include <conio.h>
  void main()
    {
   clrscr();
    int a[10][10],m,n,i,j;
    cout<<"Enter number of rows: ";
    cin>>m;
    cout<<"Enter number of coloumns: ";
    cin>>n;
  
    if(m!=n)
    {
    cout<<"Matrix not square so Transpose not possible :(";
    }
    else
    {
    cout<<endl<<"Enter elements of matrix: "<<endl;
    for(i=0;i<m;i++)
    {
    for(j=0;j<n;j++)
    {
    cout<<"Enter element a"<<i+1<<j+1<<": ";
    cin>>a[i][j];
    }
    }
   cout<<endl<<"Displaying Matrix: "<<endl<<endl;
 for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
   {
   cout<<a[i][j]<<" ";
   }
  cout<<endl<<endl;
   }
   cout<<endl<<"Displaying Matrix Transpose: "<<endl<<endl;
   for(i=0;i<m;i++)
   {
   for(j=0;j<n;j++)
  {
   cout<<a[j][i]<<" ";
   }
   cout<<endl<<endl;
   }
  }
  getch();
  }

please try if there are mistakes please in the comments and hopefully useful ^_^


0 komentar:

Posting Komentar