Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Determinação dos primeiros k termos da série de Fibonacci, usando uma função recursiva:
- f(0) = f(1) = 1; f(n) = f(n - 1) + f(n - 2) para n = 2, 3, ... */
- // Apple Xcode
- #include <stdio.h>
- int func_fibonacci(int the_k)
- {
- // calculo recursivo da serie de Fibonacci
- if (the_k == 0 || the_k == 1)
- {
- return 1;
- }
- else
- {
- return func_fibonacci(the_k - 1) + func_fibonacci(the_k - 2);
- }
- }
- int main (int argc, const char * argv[])
- {
- // serie de Fibonacci
- int i, the_n;
- printf("N de termos: ");
- scanf("%d", &the_n);
- // parametros iniciais
- for (i = 0; i < the_n; i++)
- {
- printf("%d, ", func_fibonacci(i));
- // mudanca de linha apos a impressao do 5 elemento
- if ((i + 1) % 5 == 0)
- {
- printf("\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement