Program to find transpose of a matrix by using multi-dimensional arrays.
Find Transpose of a Matrix by Using Multi-dimensional Arrays
Object: Write a C++ program to find transpose of a matrix by using multi-dimensional arrays. C++ Projects
Code:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int mat[4][5],i,j;
cout<<“Enter matrix values:\n”;
for(i=0;i<4;i++)
{
for(j=0;j<5;j++)
{
cin>>mat[i][j];
}
}
cout<<endl;
for(i=0;i<4;i++)
{
cout<<“[ “;
for(j=0;j<5;j++)
{
cout<<mat[i][j]<<” “;
}
cout<<“]”<<endl;
}
cout<<” \nTranspose of the matrix is:\n”;
for(i=0;i<5;i++)
{
cout<<“[ “;
for(j=0;j<4;j++)
{
cout<<mat[j][i]<<” “;
}
cout<<“]”<<endl;
}
getch();
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include<iostream> #include<conio.h> using namespace std; void main() { int mat[4][5],i,j; cout<<"Enter matrix values:\n"; for(i=0;i<4;i++) { for(j=0;j<5;j++) { cin>>mat[i][j]; } } cout<<endl; for(i=0;i<4;i++) { cout<<"[ "; for(j=0;j<5;j++) { cout<<mat[i][j]<<" "; } cout<<"]"<<endl; } cout<<" \nTranspose of the matrix is:\n"; for(i=0;i<5;i++) { cout<<"[ "; for(j=0;j<4;j++) { cout<<mat[j][i]<<" "; } cout<<"]"<<endl; } getch(); } |
1 Response
[…] Program to find transpose of a matrix by using multi-dimensional arrays. […]