Advertisement
Guest User

[][] Flip

a guest
Jul 24th, 2012
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int array[4][4] {{   96, 26, 31, 81 },
  6.     {   41, 71, 66, 56 },
  7.     {   61, 51, 46, 76 },
  8.     {   36, 86, 91, 21 }
  9. };
  10.  
  11. int flippedArray[4][4] {{   0, 26, 31, 0 },
  12.     {   41, 0, 0, 56 },
  13.     {   61, 0, 0, 76 },
  14.     {   0, 86, 91, 0 }
  15. };
  16.  
  17. void printArray()
  18. {
  19.     for(int row = 0; row < 4; row++)
  20.     {
  21.         for (int col = 0; col < 4; col++)
  22.         {
  23.  
  24.             cout << array[row][col] << "\t";
  25.  
  26.         }
  27.         cout << endl;
  28.     }
  29.  
  30.     cout << endl;
  31. }
  32.  
  33. void printFlippedArray()
  34. {
  35.     for(int row = 0; row < 4; row++)
  36.     {
  37.         for (int col = 0; col < 4; col++)
  38.         {
  39.  
  40.             cout << flippedArray[row][col] << "\t";
  41.  
  42.         }
  43.         cout << endl;
  44.     }
  45.     cout << endl;
  46. }
  47.  
  48. void reverseLeft()
  49. {
  50.  
  51.     int newRow= 3;
  52.     int newCol = 3;
  53.     int counter = 0;
  54.  
  55.     for(int row = 0; row < 4; row++)
  56.     {
  57.         for (int col = 0; col < 1; col++)
  58.         {
  59.             flippedArray[newRow][newCol] = array[row][counter];
  60.         }
  61.  
  62.         counter++;
  63.         newRow--;
  64.         newCol--;
  65.  
  66.     }
  67.  
  68. }
  69.  
  70. void reverseRight()
  71. {
  72.  
  73.     int newRow= 3;
  74.     int newCol = 0;
  75.  
  76.     int counter = 3;
  77.  
  78.     for(int row = 0; row < 4; row++)
  79.     {
  80.         for (int col = 0; col < 1; col++)
  81.         {
  82.             flippedArray[newRow][newCol] = array[row][counter];
  83.         }
  84.  
  85.         counter--;
  86.         newRow--;
  87.         newCol++;
  88.  
  89.     }
  90.  
  91. }
  92.  
  93. int main()
  94. {
  95.     printArray();
  96.     reverseLeft();
  97.     reverseRight();
  98.     cout << endl;
  99.     printFlippedArray();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement