Advertisement
Guest User

q 1

a guest
Mar 23rd, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <array>
  2. #include<iostream>
  3. using namespace std;
  4. void tranpose(int ,int );
  5. void display (int ,int );
  6. void flip();
  7. int matrix1[3][3], matrix2[3][3]; // size of array
  8. int main()
  9. {
  10.     int i,j;
  11.     cout<<"Enter the elements of Matrix(3X3) :" <<endl; // entering values for the array
  12.     for(i=0;i<3;i++)
  13.     {
  14.         for(j=0;j<3;j++)
  15.         {
  16.             cin>>matrix1[i][j];
  17.         }
  18.     }
  19.     cout<<"Inputed matrix is: "<<endl; // displays the original array
  20.     for(i=0;i<3;i++)
  21.     {
  22.         for(j=0;j<3;j++)
  23.         {
  24.             cout<<matrix1[i][j]<<" ";
  25.         }
  26.         cout<<endl;
  27.     }
  28.     tranpose(i,j);
  29.     cout<<endl;
  30.     display(i,j);
  31.     cout<<endl;
  32.     flip();
  33.     cout<<endl;
  34.     cout<<"90 degrees flip from original input.";
  35.     cout<<"\n";
  36.     display(i,j);
  37.     return 0;
  38. }
  39. void display(int i,int j) // display function
  40. {
  41.     for(i=0;i<3;i++)
  42.     {
  43.         for(j=0;j<3;j++)
  44.         {
  45.             cout<<matrix2[i][j]<<" ";
  46.         }
  47.         cout<<endl;
  48.     }
  49. }
  50. void tranpose (int i,int j){ // transpose function
  51.     cout<<"Transpose of entered matrix";
  52.     for(i=0;i<3;i++)
  53.     {
  54.         for(j=0;j<3;j++)
  55.         {
  56.             matrix2[i][j]=matrix1[j][i];
  57.         }
  58.     }
  59. }
  60. void flip()
  61. {
  62.     int array[3];
  63.  
  64.     for(int i=0; i<3;i++)
  65.     {       //saving first column
  66.         array[i] = matrix2[i][0];
  67.     }
  68.  
  69.     for(int j=0; j<3;j++)
  70.     {       //moving last into first
  71.         matrix2[j][0] = matrix2[j][2];
  72.     }
  73.     for(int k=0; k<3;k++)
  74.     {       //moving saved into last
  75.         matrix2[k][2] = array[k];
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement