C Program to find smallest element in array using recursion

Simple C program to find smallest element in array using recursion: If array is {20,45,13,54,17} then program will print 13. In this array smallest element is 13.
/*Find Smallest element in array */ 
#include<stdio.h>
int min(int a,int b)
{
 if(a>b)
 return b;
 return a;
}
int FindMin(int arr[],int n)
{
 if(n==0)
 return arr[0];
 return min(FindMin(arr,n-1),arr[n]);
}
int main()
{
 int arr[6]={30,20,9,4,10,6};
 /* FindMin(arr,size of array -1) */
 int Min_value=FindMin(arr,5);
 printf("%d ",Min_value);
 return 0;
}
/* End of the program */ 



Popular posts from this blog