Advertisement
Guest User

Câu 2

a guest
Feb 23rd, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 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 aRow, int aColumn, int bRow, int bComlumn)
  33. {
  34.     int t = 2;
  35.    
  36.     for (int j = 0; j < aColumn; j++)
  37.     {
  38.         int k = 0;
  39.        
  40.         for (int i = 0; i < aRow; i++)
  41.         {
  42.             b[i][t] = a[j][k];
  43.             k++;
  44.         }
  45.         t--;
  46.     }
  47. }
  48.  
  49. int main() {
  50.     int a[100][100];
  51.     int b[100][100];
  52.     int aRow= 3, aColumn = 3, bRow = 3, bColumn = 3;
  53.     ImportMaxtrix(a, aRow, aColumn);
  54.     PrintMatrix(a, aRow, aColumn);
  55.     Rotate90(a, b, aRow, aColumn, bRow, bColumn);
  56.     cout << endl;
  57.     PrintMatrix(b, bRow, bColumn);
  58.     system("pause");
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement