Originally Posted by
Duki
seeing as this is being discussed still, I would like to pose another question: How do I use an array using recursion? This will be more efficient, no? Here is my current code:
#include <iostream>
using namespace std ;
int fib ( int ) ;
int main ( )
{
int i = fib ( 5 ) ;
cout << i << endl ;
return 0 ;
}
int fib ( int n )
{
int fibArray [ const n ] ;
if ( <= 1 )
return 1 ;
else
{
fibArray[ 0 ] = 1 ;
fibArray[ 1 ] = 1 ;
for ( int i = 2 ; i < 25 ; i++ )
fibArray[ i ] = ( fib ( n - 1 ) + ( fib ( n - 2 ) ) ) ;
}
return fibArray[ n ] ;
}
why can i not do int fibArray [ n ] ? It says "expected constant"
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.
-Edsger Dijkstra