// Program to display Fibonacci series using recursion. // Assignment-11 // fibrec.cpp, Author - Krishna Kumar Khatri. // Uncomment ONLY the following line if you are using Turbo/Borland compiler. // #define TC #ifdef TC #include #else #include using namespace std; #endif #include // For getch. int fib(const int n) { return (n == 0 || n == 1) ? 1 : (fib(n - 1) + fib(n - 2)); } void fibonacci(int num) { while (num >= 0) (num - 1) >= 0 ? cout << fib(num--) << ", " : cout << fib(num--); } int main() { #ifdef TC clrscr(); #endif int num; do { cout << "Enter the number of terms to be generated: "; cin >> num; } while (num < 1); cout << endl << "The desired Fibonacci series is, "; fibonacci(num - 1); cout << endl << endl << "Program over. Press any key to exit..."; getch(); return 0; // Successful termination. }