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

Respuesta :

Answer:

Answer is provided in the Explanation section

Explanation:

#include <stdio.h>

// 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