Thursday 5 July 2012

program to display transpose of matrix using c++ .

#include<iostream>
using namespace std;

int main()
{
int i,j,rows,cols;
   
    lable:
    cout<<"Enter your total number of rows ";
    cin>>rows;
    cout<<endl;
    cout<<"Enter your total number of cols ";
    cin>>cols;
    if (rows!=cols)
    {
    cout<<"rows and cols are not equal"<<endl;
    goto lable;
    }
    int a[rows][cols];
    cout<<endl<<"enter element for array"<<endl;

        for(i=0;i<rows;i++)
        {
        for(j=0;j<cols;j++)
        {
        cout<<"a"<<"["<<i<<"]"<<"["<<j<<"]" <<"   :   ";
        cin>>a[i][j];
        cout<<endl;
        }
       
        }
cout<<"your matrix is: "<<endl;
for(i=0;i<rows;i++)
        {
        for(j=0;j<cols;j++)
        {

        cout<<a[i][j];
        cout<<"        ";

       
        }
cout<<endl;
        }
cout<<"transpose of matrix is :  "<<endl;
        for(i=0;i<rows;i++)
        {
        for(j=0;j<cols;j++)
        {
       
        cout<<a[j][i];
        cout<<"        ";
        }
cout<<endl;
        }
return 0;
}

No comments:

Post a Comment