100 points if you give a solution to this question.
write a Fibonacci Algorithm (or a program using a C programming language) to calculate the nth (number n). of the Fibonacci sequence.
notice that U(0)=0 ; U(1)=1 ; U(n)=U(n-1)+U(n-2)

Respuesta :

Answer:

Fn=(Fn−1+Fn−2) F n = ( F n − 1 + F n − 2 ) , where n >1.

Explanation:

TJC07

Answer: Here is the solution in C. This works programmatically. Feel free to alter it if there are any garbage collection issues.

Explanation:

#include <stdio.h>

int fib(int num) {

   if (num <= 0) return 0;

   else if (num == 1) return 1;

   

   int fst = 0;

   int snd = 1;

   int sum = fst + snd;

   for (int n = 0; n < num; ++n) {

       sum = fst + snd;

       fst = snd;

       snd = sum;

   }

   return fst;

}

int main()  {

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

   return 0;

}