fork download
  1. #include<stdio.h>
  2.  
  3. int rec(int a[],int low,int high){
  4. if(low>=high)
  5. return a[low]==42?1:0;
  6. else
  7. return rec(a,low,(low+high)/2)+rec(a,(low+high)/2+1,high);
  8. }
  9. int main(){
  10. int n;
  11. printf("Enter the value to be found:",n);
  12. scanf("%d",&n);
  13. int size;
  14. scanf("%d",&size);
  15. int a[size];
  16. for(int i=0;i<size;i++)scanf("%d",&a[i]);
  17. int ans=rec(a,0,size);
  18. printf("%d\n",ans);
  19. }
Success #stdin #stdout 0s 4336KB
stdin
42
2
42 4
stdout
Enter the value to be found:1