Advertisement
AlexandruFilipescu

Transpusa unei matrici c++

Nov 11th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <stdio.h>
  4.  
  5. using namespace std;
  6. #define nr_lin 3
  7. #define nr_col 2
  8.  
  9. int main() {
  10.     srand(time(0));
  11.     int i, j,nr_inc=1, mat[nr_lin][nr_col], mat2[nr_col][nr_lin];
  12.  
  13.     for (i = 0; i < nr_lin; i++) {
  14.         for (j = 0; j < nr_col;j++) {
  15.             mat[i][j] = nr_inc++;
  16.         }
  17.     }
  18.  
  19.     cout << endl;
  20.  
  21.     for (i = 0; i < nr_lin; i++) {
  22.         for (j = 0; j < nr_col; j++) {
  23.             cout << mat[i][j] << " ";
  24.         }
  25.         cout << endl;
  26.     }
  27.  
  28.     cout << endl;
  29.    
  30.     for (j = 0; j < nr_col;j++) {
  31.         for (i = 0; i < nr_lin;i++) {
  32.             mat2[j][i] = mat[i][j];
  33.         }
  34.    
  35.     }
  36.  
  37.     for (i = 0; i < nr_col; i++) {
  38.         for (j = 0; j < nr_lin; j++) {
  39.             cout << mat2[i][j] << " ";
  40.         }
  41.         cout << endl;
  42.     }
  43.  
  44.  
  45.     system("pause");
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement