fork download
  1. #include <stdio.h>
  2.  
  3. #define n 10
  4.  
  5. int occ(int *p,int dim,int X);
  6.  
  7. int main() {
  8. int v[n]={4,7,8,0,2,12,4,2,63,10}; //it is only an example
  9. int X=0;
  10. int ok;
  11. ok=occ(v,n,X);
  12. if(ok){
  13. printf("\n%d\nFound!",X); //check if the recursive function works properly
  14. }
  15. return 0;
  16. }
  17.  
  18. int occ(int *p,int dim,int X){
  19.  
  20. int pivot,a=0,b=0;
  21. pivot=(dim)/2;
  22. if(dim==0){
  23. return 0;
  24. }
  25.  
  26. if(*(p+pivot)==X)
  27. return 1;
  28.  
  29. if (pivot != 0)
  30. {
  31. a=occ(p,pivot,X);
  32. b=occ(p+pivot,dim-pivot,X);
  33. }
  34.  
  35. if(a+b>=1)
  36. return 1;
  37. else{
  38. return 0;
  39. }
  40. }
  41.  
  42.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
0
Found!