Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- int A[n][n] ;
- // input matrix
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cin >> A[i][j];
- }
- }
- int min_element = A[0][0], min_col = 0;
- // find the first minimal element on the main diagonal and its column
- for (int i = 0; i < n; i++)
- {
- if (A[i][i] < min_element)
- {
- min_element = A[i][i];
- min_col = i;
- }
- }
- int row;
- cin >> row;
- // swap the column with the minimal element on the main diagonal with the specified row
- for (int i = 0; i < n; i++)
- {
- swap(A[i][min_col], A[i][row]);
- }
- // output the new matrix
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cout << A[i][j] << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment