Advertisement
Guest User

bài 2

a guest
Feb 23rd, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. /*
  5. a[][100]: matrix a
  6. aRow: row number of matrix a
  7. aColumn: column number of matrix a
  8. */
  9. void ImportMaxtrix(int a[][100], int aRow, int aColumn)
  10. {
  11.     for (int i = 0; i < aRow; i++)
  12.         for (int j = 0; j < aColumn; j++)
  13.         {
  14.             cout << "A[" << i << "][" << j << "] = ";
  15.             cin >> a[i][j];
  16.         }
  17. }
  18.  
  19. void PrintMatrix(int a[][100], int aRow, int aColumn)
  20. {
  21.     for (int i = 0; i < aRow; i++)
  22.     {
  23.         for (int j = 0; j < aColumn; j++)
  24.         {
  25.             cout << a[i][j];
  26.             cout << "   ";
  27.         }
  28.         cout << endl;
  29.     }
  30. }
  31. //Rotate matrix 90 degree
  32. void Rotate90(int a[][100], int b[][100], int hang, int cot)
  33. {
  34.     for (int i = 0; i <= hang - 1; i++)
  35.     {
  36.         for (int j = 0; j <= cot - 1; j++)
  37.         {
  38.             cout << endl;
  39.             for (int k = hang - 1; k >= 0; k--)
  40.             {
  41.                 b[j][i] = a[k][j];
  42.                 cout << b[j][i] << "   ";
  43.             }
  44.         }
  45.     }
  46. }
  47.  
  48. int main() {
  49.     int a[100][100];
  50.     int b[100][100];
  51.     int aRow = 3, aColumn = 3, bRow = 3, bColumn = 3;
  52.     ImportMaxtrix(a, aRow, aColumn);
  53.     PrintMatrix(a, aRow, aColumn);
  54.     Rotate90(a, b, aRow, aColumn );
  55.     cout << endl;
  56.     PrintMatrix(b, bRow, bColumn);
  57.     system("pause");
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement