Advertisement
AbraaoAllysson

menor valor de forma recursiva

May 15th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <limits.h> //INT_MAX
  3.  
  4. int menorValor(int vet[], int tam, signed int temp);
  5.  
  6. int main(void)
  7. {
  8.     int vetor [] = {100,7,10,1000,-2,9,38,400,500,1,-500};
  9.    
  10.     printf("menor valor:    %d",menorValor(vetor,10,INT_MAX) );
  11.        
  12.     return 0;
  13. }
  14.  
  15. int menorValor(int vet[], int tam, signed int temp)
  16. {
  17.  
  18.     if(temp > vet[tam] ) // verificar se temp é maior do que elemento do vetor se for atualiza
  19.     {
  20.         temp=vet[tam];
  21.     }
  22.     if(tam==0) //critério de parada da recursividade
  23.     {
  24.         return temp;
  25.     }
  26.                          
  27.  return menorValor(vet, tam -1,temp);
  28.    
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement