C Program to find largest element of array using recursion

Simple C program to find largest element of array using recursion: If array is {3,7,4,9,2,20,2,1} then it will print 20.
/* C Program to find largest element of array */
#include<stdio.h>
int max(int a,int b)
{
 if(a>b)
 return a;
 return b;
}
int LargestElement(int arr[],int n)
{
 if(n==0)
 return arr[0];
 return max(LargestElement(arr,n-1),arr[n]);
}
int main()
{
      int arr[6]={23,65,34,120,20,30};
      /* LargestElement(arr,size-1) */
    int Max_Element=LargestElement(arr,5);
    printf("Largest Element in array = %d",Max_Element);
    return 0;
}
/* End of the program */



Popular posts from this blog