Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. <?php
  2.  
  3. $lista = [3, 29, 18, 10, 8, 15];
  4. $numero = 18;
  5.  
  6. function encuentraPar(array $lista, int $numero)
  7. {
  8.     $par = [];
  9.     foreach ($lista as $valor) {
  10.         if ($valor >= $numero) {
  11.             continue;
  12.         } else {
  13.             $resto = $numero - $valor;
  14.  
  15.             if (in_array($resto, $lista)) {
  16.                 $par = [$valor,  $resto];
  17.                 break;
  18.             }
  19.         }
  20.     }
  21.     return $par;
  22. }
  23.  
  24. print_r(encuentraPar($lista, $numero));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement