at each call, arr[n] is same despite the changing value of n.
code : https://ide.codingblocks.com/s/160368
Getting incorrect output
The approach you are using is wrong, You need to change the function as, the parameters will be
int foundlast(ar,0,N,M);
Modify your function as ,
int foundlast(int ar[],int curr_index,int N,int M)
{
if(curr_index==N)
{
return -1;
}
int index=foundlast(ar,curr_index+1,N,M);
if(index==-1 && ar[curr_index]==M)
{
return curr_index;
}
else
{
return index;
}
}
Try to use this approach instead wht u have used…
Since, you arent replying anything, I am marking this doubt as resolved, You can reopen it if you still face any issues…