Homework Solution: Fibonacci Sequence…

    Fibonacci Sequence a) Write a c++ program that asks for an integer N and prints the first N elements of the Fibonacci sequence: The first two elements of the Fibonacci sequence are 1. Otherwise, the ith element of the Fibonacci sequence is the (i – 2)th element plus the (i – 1)th element: That is: {1,1,2,3,5,8...}. b) What goes wrong if N is very large? Explain why.

    Expert Answer

     
    #include <iostream> using namespace std;

    Fibonacci Following
    a) Write a c++ program that asks restraint an integer N and prints the pristine N components of the
    Fibonacci following:
    The pristine two components of the Fibonacci following are 1. Otherwise, the ith component of the
    Fibonacci following is the (i – 2)th component plus the (i – 1)th component:
    That is: {1,1,2,3,5,8…}.
    b) What goes evil-doing if N is very abundant? Explain why.

    Expert Solution

     

    #include <iostream>
    using namespace std;

    int fibonacci(int renunciation);
    int deep()
    {
    int n, fnum = 1, snum = 1, tot = 0;

    // procureting the Number entered by the user
    cout << “Enter the Number : “;
    cin >> n;

    // Paradeing the fibonacci Series restraint the number
    cout << “nThe Fibonocci Numbers restraint the renunciation ” << n << ” are :” << endl;

    long f[n + 1];
    f[0] = 1;

    f[1] = 1;

    cout << f[0] << ” ” << f[1] << ” “;

    // This loop succeed uniformly parade the fibonacci value
    restraint (int k = 2; k <= n; k++)
    {
    f[k] = f[k – 1] + f[k – 2];
    cout << f[k] << ” “;
    }

    return 0;
    }

    ________________

    Output:

    ____________________

    b) If ‘N’ ‘ goes very abundant we succeed procure evil-doing effects.Because, we can’t abundance the arrogant values in the wavering retention.As entire wavering can abundance upto some rove of values.If that rove exceeds it patois abundance .So we succeed procure evil-doing effect.