Thursday 31 January 2013

transpose of a matrix in c++

#include<iostream.h>
#include<conio.h>
void main()
{

int r,c,i,j;
int matrix[12][12];
int transpose[12][12];

cout<<"enter no of rows of matrix      ";
cin>>r;
cout<<"enter no of columns of matrix   ";
cin>>c;

cout<<"\n\n";
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{cout<<"matrix["<<i<<"]["<<j<<"]"<<"    ";
cin>>matrix[i][j];}

   cout<<"\n\nMATARIX IS\n\n";
    cout<<"\n\n";
    for(i=0;i<r;i++)
    {for(j=0;j<c;j++)
    cout<<matrix[i][j]<<"\t";
    cout<<endl<<endl;}

   cout<<"TRANSPOSE IS\n\n";
    for(i=0;i<c;i++)
    {for(j=0;j<r;j++)
    cout<<matrix[j][i]<<"\t";
    cout<<endl<<endl;}


getch();
}

0 comments:

Post a Comment