Advertisement
DrAungWinHtut

2darray.cpp

Jul 31st, 2023
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4.    
  5.     const int rows = 3;
  6.     const int cols = 4;
  7.     int temp[4] = { 0 };
  8.     int matrix[rows][cols] = {
  9.         {1, 2, 3, 4},
  10.         {5, 6, 7, 8},
  11.         {9, 10, 11, 12}
  12.     };
  13.    
  14.     // temp = row0 , row0=row1, row1 = temp
  15.     for (int i = 0; i < cols; i++)
  16.     {
  17.         temp[i] = matrix[0][i];
  18.     }
  19.     for (int i = 0; i < cols; i++)
  20.     {
  21.         matrix[0][i] = matrix[1][i];
  22.     }
  23.     for (int i = 0; i < cols; i++)
  24.     {
  25.         matrix[1][i] = temp[i];
  26.     }
  27.    
  28.  
  29.     for (int r = 0; r < rows; r++)
  30.     {
  31.         for (int c = 0; c < cols; c++)
  32.         {
  33.             cout << "   "<<matrix[r][c] << "   ";
  34.         }
  35.         cout << endl;
  36.     }
  37.  
  38.     return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement