Advertisement
MargaritaOwl

Row = Column(dinamic+static mas)

May 14th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include<iomanip>
  3. #include<ctime>
  4. using namespace std;
  5. void main()
  6. {
  7.     srand(time(NULL));
  8.     //const int n = 20;
  9.     long int n = rand() % 5000;
  10.     int **mas = new int*[n];
  11.     int k = rand() % n;
  12.     //int mas[n][n];
  13.     for (int i = 0; i < n; i++)
  14.     {
  15.         mas[i] = new int[n];
  16.         for (int j = 0; j < n; j++)
  17.             mas[i][j] = rand() % 2000 - 100;
  18.     }
  19.     cout << "Source array:" << endl;
  20.     for (int i = 0; i < n; i++)
  21.     {
  22.         for (int j = 0; j < n; j++)
  23.             cout << setw(4) << mas[i][j];
  24.         cout << endl;
  25.     }
  26.     //cout << "Enter number of column:";
  27.     //cin >> k;
  28.     for (int i = 0; i<n; i++)
  29.         for (int j = 0; j < n; j++) {
  30.             if (i == k) mas[i][j] = mas[j][k];
  31.             else
  32.             {
  33.                 mas[i][j] = mas[i][j];
  34.             }
  35.         }
  36.     cout << "Result array:" << endl;
  37.     for (int i = 0; i < n; i++)
  38.     {
  39.         for (int j = 0; j < n; j++)
  40.             cout << setw(4) << mas[i][j];
  41.         cout << endl;
  42.     }
  43.     for (int i = 0; i < n; i++) {
  44.         delete[]mas[i];
  45.     }
  46.     delete[]mas;
  47.     system("pause");
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement