# Thread: recursive finding index of the min number in array??

1. ## recursive finding index of the min number in array??

Code:
```int min_num(int arr[],int index, int minIndex, int size){

if (index==size)
return minIndex;
else
if (arr[index]<arr[minIndex])
minIndex=index;

min_num(arr,index+1,minIndex,size);
}```
size=4;
index=1;
minindex=1;

if i have array={3,2,5,1}
i need find index of the minimum number in the array

minIndex=3, because 1 is the minimum number,,
but this returning 0!! why??
how i can return 3!!???

2. array subscripts start at zero in C so go over this again
Code:
`if (index==size)`
Edit: never mind I did not read the code only the section below.

size=4;
index=1;
minindex=1;

3. Your missing a return for your recursive steps. the last line should be return followerd by your function call.

4. Code:
```int min_num(int arr[],int index, int minIndex, int size){

if (index==size)
return minIndex;
else
if (arr[index]<arr[minIndex])
minIndex=index;

return min_num(arr,index+1,minIndex,size);
}```
it doesn`t help
still returning 0!!

5. How do you call it? Post the main function.

6. since array indexing starts at 0,thus u should pass the value of index as 0.if index=1 is passed the code will start comparing the elements from arr[1] leaving the first element ignored.also if u're calling this function from main it should return its value to some variable and that variable should get printed.
in main
Code:
`k=min_num(arr,0,1,4);`
hope it helps.