fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iterator>
  4. using namespace std;
  5.  
  6. int main() {
  7. const size_t N = 3;
  8. int m[N][N] = {
  9. {1, 2, 3},
  10. {4, 7, 2},
  11. {8, 2, 5}
  12. };
  13.  
  14. for (size_t i = 0; i < N; ++i) {
  15. int* mx = max_element(m[i], m[i] + N);
  16. swap(m[i][i], *mx);
  17. copy(m[i], m[i] + N, ostream_iterator<int>(cout, " "));
  18. cout << endl;
  19. }
  20. }
Success #stdin #stdout 0.01s 2680KB
stdin
Standard input is empty
stdout
3  2  1  
4  7  2  
5  2  8