C++ Programme to find the transpose of a matrix

program to find the transpose of a matrix

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],b[10][10],i,j,r1,r2,c1,c2;
cout<<"enter rows and column\n";
cin>>r1>>c1;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cin>>a[i][j];
}
}
cout<<"\n";
cout<<"this matrix a\n";

for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
cout<<"\t"<<          a[i][j];
}
cout<<"\n";
}
cout<<"Tronspose\n";
for(i=0;i<c1;i++)
{
for(j=0;j<r1;j++)
{
b[i][j]=a[j][i];
}
}
for(i=0;i<c1;i++)
{
for(j=0;j<r1;j++)
{
cout<<"\t"<<b[i][j];
}

cout<<"\n";
}

getch();
}



OUTPUT:
enter rows and column
3
4


1
2                                                                              
3                                                                              
4                                                                               
5                                                                              
6                                                                              
7                                                                               
8                                                                              
9                                                                              
10                                                                              
12                                                                             
13                                                                             
                                                                                
this matrix a 
                                                                 
        1       2       3       4                                              
        5       6       7       8                                               
        9       10      12      13                                             

Transpose 
                                                                     
        1       5       9                                                      
        2       6       10                                                     
        3       7       12                                                     
        4       8       13

No comments:

Post a Comment