Solution :
#include <iostream>
using namespace std;
//Function Declaration
int max(int arr[],int size);
int main()
{
//Declaring variable
int size;
while(true)
{
cout<<"Enter the no of elements in the array :";
cin>>size;
if(size<=0)
{
cout<<"Invalid.Must be greaterthan Zero"<<endl;
continue;
}
else
break;
}
//Creating an array
int arr[size];
/* getting the inputs entered by
* the user and populate them into array
*/
for(int i=0;i<size;i++)
{
cout<<"Enter element#"<<i+1<<":";
cin>>arr[i];
}
//calling function
int maximum=max(arr,size);
//Displaying the output
cout<<"The maximum Element in the Array is :"<<maximum<<endl;
return 0;
}
/* Function implementation which finds
* the maximum element in the array and return it
*/
int max(int arr[],int size)
{
//Declaring the static variables
static int k=0,maximum=-999;
/* This if block will execute only if the value of k
* is less than the size of an array
*/
if(k==size-1)
{
return arr[0];
}
else if(size-1>k)
{
if(arr[k]>maximum)
maximum=arr[k];
//Incrementing the k value
k++;
//Calling the function
max(arr,size);
}
return maximum;
}