Advertisement
Need4Sleep

main.cpp (DailyC++) 7/24/12

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