15,667,014 members
See more:
create a function to find the number in between using recursion
`int within(int a[], int N, int lower, int upper, int result[])`
Input:
int a[] = {4, 1, 3, 1, 3, 2};

Output range between 2 to 3:
{3,3,2}, count = 3

What I have tried:

```int within(int a[], int N, int lower, int upper, int result[])
{
int count = 0;
if (N == 1 && a[0] >= lower && a[0] <= upper) return a[0]; // base case
for(int i = 0; i < N - 1; i ++){
if (a[i] >= lower && a[i] <= upper){
return within(&a[0], N - 1, lower, upper,result);
count++;
}
return count;
}
}```
Posted
Updated 6-Mar-18 3:04am
v2

Solution 2

C++
```return within(&a[0], N - 1, lower, upper,result);
count++; // this will never be executed, as it follows a return statement
```

Solution 1

the compiler probably complain that 'all path do not have a return'
C++
```int within(int a[], int N, int lower, int upper, int result[])
{
int count = 0;
if (N == 1 && a[0] >= lower && a[0] <= upper) return a[0]; // base case
for(int i = 0; i < N - 1; i ++){
if (a[i] >= lower && a[i] <= upper){
return within(&a[0], N - 1, lower, upper,result);
count++;
}
return count;
}
// because a return is missing here
}```

your requirement make no sense to me. I don't see how you can get 4 as output with the sample input.
Your code also make no sense to me. I don't see its logic.