I'm trying to write a recursive function that returns the sum of odd numbers from an array.
It's not really working but I can't figure out why.
Any help would be appreciated,
thanks,
#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;
}
This post has been edited by marcelomg: 07 March 2010 - 06:53 PM

New Topic/Question
Reply



MultiQuote




|