rLS finds the first matching occurrence of k in array a starting at position s moving backwards through array a (by subtracting 1 on the recursive call)
#include <iostream>
usingnamespace std;
void rLS (int* a, int k, int s)
{
if (s <= 0)
cout << k << " not found\n";
elseif (a[--s] == k)
cout << k << " found at offset " << s << "\n";
else
rLS(a, k, s);
}
int main()
{
int a[] { 1, 3, 5, 7, 9, 11, 13 };
int s = sizeof a / sizeof *a;
rLS(a, 5, s);
rLS(a, 9, s);
rLS(a, 10, s);
}