#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//void largest_recursive(int ar[], int size);
int largest_recursive(int ar[], int size) {
int tmp;
int ret;
if (size > 1) {
tmp = largest_recursive(ar, size-1);
}
if (ar[size] > ar[size-1]) {
ret = ar[size];
} else {
ret = ar[size-1];
}
if (tmp > ret) {
ret = tmp;
}
return ret;
}
int main () {
int ar[101]={0}; //the array
srand(time(0));
for (int a=0; a<=100; a++) //counter
{
ar[a]=rand()%25+1;
}
cout << largest_recursive(ar, 100);
system("pause");
return 0;
}
Works, though I just noticed that half of the comparisons are pointless. I won't comment on it, just figure it out yourself.