0% found this document useful (0 votes)
24 views2 pages

A2 Ques1

Data structures practicals in c++

Uploaded by

mussu0224
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

A2 Ques1

Data structures practicals in c++

Uploaded by

mussu0224
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/*Q1.

Give a C++ code function that, given a n × n matrix M of type


float, replaces M with its transpose without the use of a temporary
matrix.*/
#include <iostream>
using namespace std;
class Matrix
{
int **a;
int row ,col;
public:
Matrix(int x=0,int y=0)
{
row=x;
col=y;
a = new int *[row];
for (int i=0;i<row;i++)
{
a[i]=new int [col];
}
for (int i=0;i<row;i++)
{
for (int j=0;j<col;j++)
{
a[i][j]=0;
}
}
}
void getvalue()
{
for (int i=0;i<row;i++)
{
for (int j=0;j<col;j++)
{
cout<<"Enter Value for A["<<i<<"]["<<j<<"] : ";
cin>>a[i][j];
}
}
}
Matrix transpose() //transpose function
{

for (int i=1;i<row;i++)


{
for (int j=0;j<col;j++)
{
int temp=a[j][i];
a[j][i]=a[i][j];
a[i][j]=temp;
}
}
}
void display()
{
for (int i=0;i<row;i++)
{
for (int j=0;j<col;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
};
int main()
{
int r1,c1;
cout<<"For Matrix 1:"<<endl<<"Enter No. of Rows:";
cin>>r1;
cout<<"Enter No. of Columns:";
cin>>c1;
Matrix mat1(r1,c1);
mat1.getvalue();
cout<<"Matrix Formed:"<<endl;
mat1.display();
mat1.transpose();
cout<<endl<<"Transpose of Given matrix is :"<<endl;
mat1.display();
return 0;
}

You might also like