fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. int main (){
  5. int n, m, arr[100][100], maxi_column = -1e9;
  6. cin >> n >> m;
  7. for(int i = 0; i < n; i++){
  8. for(int j = 0; j < m; j++){
  9. cin >> arr[i][j];
  10. }
  11. }
  12. cout << "Maximum of each column: ";
  13. for(int j = 0; j < m; j++){
  14. for(int i = 0; i < n; i++){
  15. maxi_column = max(maxi_column, arr[i][j]);
  16. }
  17. cout << maxi_column << " ";
  18. maxi_column = -1e9;
  19. }
  20. }
  21.  
Success #stdin #stdout 0.01s 5304KB
stdin
3 4
1 2 3 4 
5 6 7 8
9 10 11 12
stdout
Maximum of each column: 9 10 11 12