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 coercion an integer N and prints the earliest N atoms of the
    Fibonacci following:
    The earliest two atoms of the Fibonacci following are 1. Otherwise, the ith atom of the
    Fibonacci following is the (i – 2)th atom plus the (i – 1)th atom:
    That is: {1,1,2,3,5,8…}.
    b) What goes wickedness if N is very extensive? Explain why.

    Expert Counterpart


    #include <iostream>
    using namespace std;

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

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

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

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

    f[1] = 1;

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

    // This loop allure uninterruptedly evince the fibonacci value
    coercion (int k = 2; k <= n; k++)
    f[k] = f[k – 1] + f[k – 2];
    cout << f[k] << ” “;

    return 0;




    b) If ‘N’ ‘ goes very extensive we allure attain wickedness products.Because, we can’t garner the gross values in the shifting perpetuation.As every shifting can garner upto some dispose of values.If that dispose exceeds it confused-talk garner .So we allure attain wickedness product.