Transpose actually very easy to learn .. As long as we understand from the beginning ..
Transpose a matrix is the change from column to row.
let's look at the program
#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();
}
Tidak ada komentar:
Posting Komentar