squillace91
3/25/2012 - 2:23 AM

Lab_AEDII_Lista04Exercicio01

Lab_AEDII_Lista04Exercicio01

/* 
 * File:   L04E02 (Fibonacci)
 * Author: squillace91
 *
 * Created on 23 de Março de 2012, 15:25
 */

#include <stdio.h>
#include <stdlib.h>

int fibonacci(int n,int *pcont) {

    *pcont = *pcont + 1;
    //printf("%d\n",n);

    if (n == 0)
        return 0;
    if (n == 1)
        return 1;
    int res = fibonacci(n - 1,pcont) + fibonacci(n - 2,pcont);

    printf("fibo(%d)=fibo(%d-1)+fibo(%d-2)\r\n",res, n,n);
    return res;
}

int main() {
    int n = 5;
    int pcont=0;

    int fib = fibonacci(n,&pcont);
    printf("fibonacci de %d é %d \n", n, fib);
    printf("Cont: %d \n",pcont);

    return (EXIT_SUCCESS);
}