Advertisement
Bidca

Máximo elemento de una matriz, con recursion (intento).

Apr 5th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. ///NOTA: Solo se puede hacer con matrices cuadradas, con 0 < n <= 30 y numeros >= 0.
  4.  
  5. int val_min (int mat [][30], int i, int j, int n, int com) {
  6.     int v_min = com;
  7.     if (i == n) {
  8.         return v_min;
  9.     } else {
  10.         if (i < n) {
  11.             if (v_min > mat [i][j]){
  12.                 v_min = mat [i][j];
  13.             }
  14.             ++j;
  15.             if (j < n) {
  16.                 val_min (mat, i, j, n, v_min);
  17.             } else {
  18.                 ++i;
  19.                 val_min (mat, i, 0, n, v_min);
  20.             }
  21.         }
  22.     }
  23.  
  24. }
  25.  
  26. int main ( ) {
  27.  
  28.     int n;
  29.     std::cin >> n;
  30.  
  31.     int mat [n] [30];
  32.  
  33.     for (int i = 0; i < n; ++i){
  34.         for (int j = 0; j < n; ++j) {
  35.             int num;
  36.             std::cin >> num;
  37.             mat [i] [j] = num;
  38.         }
  39.     }
  40.  
  41.    int comienzo = mat [0][0];
  42.     std::cout << val_min (mat, 0, 1, n, comienzo) << "\n";
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement