I have to find the largest item in an arry as a recursive function. Can't seem to get it right. Any ideas.
#include <iostream>
using namespace std;
int maxArray( int anArray[], int n );
int main()
{
int anArray[4] = { 1, 6, 8, 3 };
cout << "the largest number of the array is " << anArray << endl;
return 0;
}
int maxArray( int anArray[], int n )
{
if( n == 0 )
{
cout << "empty array" << endl;
}
if( n == 1 )
{
return anArray[0];
}
else
{
anArray[n] = maxArray( anArray, n-1 );
}
if( anArray[n] > anArray[n] )
{
return anArray[n];
}
else
{
return anArray[n];
}
}