//############################################################################### // A recursive function to find the index of the minimum number in an array. // Denote the array by a[0..size-1], where "0..size-1" is the range of the valid // index. // The idea is to find out the index of the minimum number is a[0..size-2]. In // other words we solve the same problem for a slightly smaller problem. That // minimum number is then compared with a[size-1], and the index of the smaller // number is the solution. // The base case is when the size of array is 1, in which case, the result is // obviously 0. //############################################################################### #include int recursive_find_min(int a[], int size) { if(size == 1) return 0; else { int idx = recursive_find_min(a, size-1); if(a[idx] <= a[size-1]) return idx; else return size-1; } } int main() { int a[] = {9,6,8,4,7}; printf("%d\n", recursive_find_min(a, sizeof(a)/sizeof(a[0]))); }