// Recursive fibonacci function. #include using std::cout; using std::cin; using std::endl; unsigned long fibonacci( unsigned long ); // function prototype int main() { unsigned long result, number; // obtain integer from user cout << "Enter an integer: "; cin >> number; // calculate fibonacci value for number input by user result = fibonacci( number ); // display result cout << "Fibonacci(" << number << ") = " << result << endl; return 0; // indicates successful termination } // end main // recursive definition of function fibonacci unsigned long fibonacci( unsigned long n ) { // base case if ( n == 0 || n == 1 ) return n; // recursive step else return fibonacci( n - 1 ) + fibonacci( n - 2 ); } // end function fibonacci