fork(4) download
  1. #include <stdio.h>
  2.  
  3. int RLinearSearch(int A[], int n, int key) {
  4. if(n<0) { // Base case - not found
  5. return -1;
  6. }
  7. if(A[n]==key) { // Base case - found
  8. return n;
  9. }
  10. // Recursive case
  11. return RLinearSearch(A, n-1, key);
  12. }
  13.  
  14. int main(void) {
  15. int A[5]={23,41,22,15,32}; // Array Of 5 Elements
  16.  
  17. int pos = RLinearSearch(A, 4, 22);
  18.  
  19. if(pos==-1)
  20. printf("Not found\n");
  21. else
  22. printf("Found at %d\n", pos);
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
Found at 2