You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
572 B
C++

Fig10_43.cpp - Inefficient recursive algorithm (see text)
#include <iostream.h>
/* START: Fig10_43.txt */
double eval( int n )
{
if( n == 0 )
return 1.0;
else
{
double sum = 0.0;
for( int i = 0; i < n; i++ )
sum += eval( i );
return 2.0 * sum / n + n;
}
}
/* END */
int main( )
{
cout << "eval( 10 ) = " << eval( 10 ) << endl;
return 0;
}