// Code-A1 (Fibonacci)

#include <iostream>
using namespace std;

// Recursive function for Fibonacci
int fibRecursive(int n) {
    if (n <= 1)
        return n;  // Base case: fib(0)=0, fib(1)=1
    return fibRecursive(n - 1) + fibRecursive(n - 2);
}

// Non-recursive (Iterative) Fibonacci
int fibIterative(int n) {
    if (n <= 1)
        return n;
    int prev = 0, curr = 1, next;
    for (int i = 2; i <= n; i++) {
        next = prev + curr;
        prev = curr;
        curr = next;
    }
    return curr;
}

int main() {
    int n;
    cout << "Enter the number of terms: ";
    cin >> n;

    cout << "\nFibonacci Series using Recursion: ";
    for (int i = 0; i < n; i++)
        cout << fibRecursive(i) << " ";

    cout << "\nFibonacci Series using Iteration: ";
    for (int i = 0; i < n; i++)
        cout << fibIterative(i) << " ";

    cout << endl;
    return 0;
}

// SAMPLE OUTPUT
/*
* $ ./a.out 
* Enter the number of terms: 5
* 
* Fibonacci Series using Recursion: 0 1 1 2 3 
* Fibonacci Series using Iteration: 0 1 1 2 3 
*/
