Recursive Function and Array
Hi !
I have a problem , what I want with my code is to output the biggest array value, but only ready the first value . There is my solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
using namespace std;
const int DIM=5;
int SearchBig(const int Array[], int Begin, int End)
{
int Bigger = Array[0];
if(Begin<End)
{
if(Array[Begin]>Bigger)
Bigger= Array[Begin];
return(SearchBig(Array, Begin, End-1));
}
else
return(Bigger);
}
int main ()
{
int Array[DIM]={15,18,21,3,10};
cout << SearchBig(Array, 1, DIM) << endl;
return (0);
}
|
You should try stepping through the code with a debugger or on paper so you can find out what's going wrong.
Topic archived. No new replies allowed.