Hello,
I'm stuck with this code and I can't figure out how to make it work. I need to get the Sum of Odd numbers from an array. For some reason it returns 0.
I'm new to programming, so any help would be appreciated, thanks.
Here it is:
#include <iostream>
using namespace std;
const int MAX = 10;
int a[ MAX ] = {1,2,3,4,5,6,7,8,9,10};
int smallResult = 0;
int sumOdd( int MAX[], int n )
{
if ( n == 0 )
return 0;
else{
int smallResult = sumOdd( MAX + 1, n - 1 );
return smallResult + MAX[ 0 ];
}
}
int main ()
{
cout << "Sum of Odd is: " << smallResult << endl;
return 0;
}