// CS2310 Exercise 20 // Chapter 18 // // Name ____________________________ SSN _______________________ // // Chapter 18. p1050 - 1 // Write a C++ value-returning function that implements the // recursive formula F(N) = F(N-1) + F(N-2) with base cases // F(0) = 1 and F(1) = 1. #include using namespace std; int F(int n) { // PRE: // n is assigned and n >= 0 // POST: // Return the value of function which is // defined as: // F(n) = F(n-1) + F(n-2) // with base case F(0) = 1 and F(1) = 1 switch (n) { case 0: // Write the return value of this base case; case 1: // Write the return value of this base case; break; default: // Write the general case here; } } int main() { int n; cout << "Enter the integer parameter (negative to quit):"; cin >> n; while (n>=0) { cout << "The Fibonachi number is: " << F(n) << endl << endl; cout << "Enter the integer parameter (negative to quit):"; cin >> n; } }