Advertisement
FOOZBY

Untitled

Dec 6th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. void rankOfMatrix(int** A, int rows, int columns) {
  2.     int rank = rows <= columns ? columns : rows;
  3.     vector<char> line_used(rows);
  4.     for (int i = 0; i < columns; ++i) {
  5.         int j;
  6.         for (j = 0; j < rows; ++j)
  7.             if (!line_used[j] && A[j][i] != 0)
  8.                 break;
  9.         if (j == rows)
  10.             --rank;
  11.         else {
  12.             line_used[j] = true;
  13.             for (int p = i + 1; p < columns; ++p)
  14.                 A[j][p] /= A[j][i];
  15.             for (int k = 0; k < rows; ++k)
  16.                 if (k != j && A[j][i] != 0)
  17.                     for (int p = i + 1; p < columns; ++p)
  18.                         A[k][p] -= A[j][p] * A[k][i];
  19.         }
  20.     }
  21.     cout << endl << "Ранг матрицы: " << rank << endl << endl;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement