Find the maximum element in an unsorted array using recursion
Recursion : Searching an array
int max(int *array, int len)
{
int n1,n2;
if(len == 1) return array[0] ;
n1 = max(array , len/2);
n2 = max(array + len/2 , len - len/2) ;
return (n1 > n2 ? n1 : n2) ;
}
int main()
{
int A[] = {2,7,91,8,9,11} ;
int B[] = {2,7,91,8,9} ;
printf("\n%d ",max(&A[0], 6));
printf("\n%d\n ",max(&B[0], 5));
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.