programming-examples/c++/Others/Fig10_43.cpp - Inefficient recursive algorithm (see text).cpp

25 lines
572 B
C++
Raw Normal View History

2019-11-15 12:59:38 +01:00
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;
}