fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void interchangeRows(int matrix[][100], int rows, int cols) {
  5. for (int j = 0; j < cols; j++) {
  6. int temp = matrix[0][j];
  7. matrix[0][j] = matrix[rows - 1][j];
  8. matrix[rows - 1][j] = temp;
  9. }
  10. }
  11.  
  12. int main() {
  13. int rows = 3, cols = 4;
  14. int matrix[100][100] = {
  15. {1, 2, 3, 4},
  16. {5, 6, 7, 8},
  17. {9, 10, 11, 12}
  18. };
  19.  
  20. interchangeRows(matrix, rows, cols);
  21.  
  22. cout << "Matrix after interchange:" << endl;
  23. for (int i = 0; i < rows; i++) {
  24. for (int j = 0; j < cols; j++) {
  25. cout << matrix[i][j] << " ";
  26. }
  27. cout << endl;
  28. }
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
Matrix after interchange:
9 10 11 12 
5 6 7 8 
1 2 3 4