Ask 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. That is, write the fib () solution as a separate function and call it in your main () function to test it

+3
Answers (1)
  1. 28 March, 18:29
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers