 Computers and Technology
27 November, 19:14

# 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

+1
Answers (1)
1. 27 November, 19:57
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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.