ToniDev

Interschimbare

May 26th, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>     /* srand, rand */
  3. #include <time.h>       /* time */
  4. using namespace std;
  5.  
  6. int A[10][10], n, m, k, aux;
  7.  
  8. void afisare() {
  9.     cout << endl;
  10.  
  11.     for (int i = 1; i <= n; i++)
  12.     {
  13.         for (int j = 1; j <= n; j++)
  14.             cout << A[i][j] << " ";
  15.         cout << endl;
  16.     }
  17.     cout << endl;
  18. }
  19.  
  20. int main()
  21. {
  22.     cout << "k: "; cin >> k;
  23.     cout << "n: "; cin >> n;
  24.  
  25.     /* initialize random seed: */
  26.     srand(time(NULL));
  27.  
  28.     /* generate secret number between 1 and 10: */
  29.     int nrGeneratRandom;
  30.  
  31.     for (int i = 1; i <= n; i++)
  32.     {
  33.         for (int j = 1; j <= n; j++)
  34.         {
  35.             nrGeneratRandom = rand() % 7 + 1;
  36.             A[i][j] = nrGeneratRandom; //Introducere date in matrice
  37.         }
  38.     }
  39.  
  40.     afisare();
  41.  
  42.  
  43.     /*Interschimbarea*/
  44.  
  45.     for (int coloana = 1; coloana < n; coloana++)
  46.     {
  47.         aux = A[k][coloana];  
  48.  
  49.         A[k][coloana] = A[coloana][k];  
  50.  
  51.         A[coloana][k] = aux;
  52.     }
  53.  
  54.  
  55.     afisare();
  56.  
  57.     cout << endl;
  58.  
  59.     return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment