C++: Write a function that accepts an 3x3 array. 1. Transpose of m x n (m rows a
ID: 3580362 • Letter: C
Question
C++: Write a function that accepts an 3x3 array.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
void transposeMatrix(int [3][3]);
int main() {
int a[3][3] = {
{1,2,3},
{4,5,6},
{7,8,9}
};
clrscr();
int i,j;
cout<<"Original Matrix Contains"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
transposeMatrix(a);
getch();
return 0;
}
void transposeMatrix(int a[3][3])
{
int i,j,temp;
for(i=0;i<3;i++)
{
for(j=i;j<3;j++)
{
temp=a[i][j];
a[i][j]=a[j][i];
a[j][i]=temp;
}
}
cout<<"Transpose Matrix Contains"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"Press Any Key to Continue...."<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.