Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.


1. Transpose of m x n (m rows and n columns) matrix involves interchanging rows and columns array. array-The below illustration shows how a 3 x 2 matrix becomes a 2 x3 rows operation (first row the transpose becomes first column, and so on). Your are asked to write a function that accepts array (already fully loaded with values, so there is no of need to have cin or cout instruction inside the function) and perform transpose operation. A sample output is provided below for your reference. Note that you must solve the problem by values in the array instead of moving values to a temporary array and then copying them to the original array. 2 fter transpose. matrix contains Press any key to continue

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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote