Advertisement
Dev4ster

Função recursiva besta

Mar 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int run(int count,int *v,int x){
  7. //achou o numero
  8. if(v[count]==x){
  9. return 1;
  10. //se a contagem chegar a 0 e a index v[0] não for igual ao meu x
  11. //retorna 0 pois não foi encontrado
  12. }else if(count==0&&v[count]!=x){
  13. return 0;
  14. //percorre todos os indexes do vetor com count diminuindo a cada
  15. //exec;
  16. }else{
  17. count--;
  18. return run(count,v,x);
  19. }
  20.  
  21. }
  22.  
  23.  
  24. int main() {
  25. int x = 11;
  26. int vetor[] = {1,2,3,4,5,6,7,8,9};
  27. int count =(sizeof(vetor)/sizeof(*vetor))-1 ;
  28.  
  29. printf("%d",run(count,vetor,x));
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement