Ask Question
14 August, 04:16

Write a iterative function that finds the n-th integer of the Fibonacci sequence. Then build a minimal program (main function) to test it. That is, write the fib () solution as a separate function and call it in your main () function to test it

+4
Answers (1)
  1. 14 August, 07:40
    0
    Answer is provided in the Explanation section

    Explanation:

    #include

    / / Function to find the nth integer of Fibonnaci sequence

    int fib (int n)

    {

    if (n < = 1)

    return n;

    int prev_num = 0, curr_num = 1;

    for (int i = 0; i < n-1; i++)

    {

    int newnum=prev_num + curr_num;

    prev_num=curr_num;

    curr_num=new_num;

    }

    return curr_num;

    }

    int main (void)

    {

    printf ("%d", fib (8));

    return 0;

    }

    Output = 21
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a iterative function that finds the n-th integer of the Fibonacci sequence. Then build a minimal program (main function) to test it. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers