(* Problemas de programação em Mathematica *)

(*Problema 8*)

(* Definir uma função de forma recursiva*)

Factor1[0] = 1;  Factor1[n_] := n * Factor1[n - 1]

Factor1[5]

Factorial[5]

Factor1[20]

Factorial[20]

Fib[0] = 0; Fib[1] = 1; 
    Fib[n_ /; n > 1] := Fib[n - 1] + Fib[n - 2]

Fib[3]

Table[Fib[k], {k, 5}]

Factor2[n_] :=  
      Module[{Prod},  Prod = 1;  Do[Prod = Prod*k, {k, n}]; 
        Prod]

Factor2[5]

Fibon[n_] := 
      Module[{termo1, termo2, termo3}, termo1 = 0; termo2 = 1; 
        Do[termo3 = termo2 + termo1; termo1 = termo2; 
          termo2 = termo3, {i, 2, n}]; termo3]

Table[Fibon[k], {k, 2, 5}]

Fibonpf[n_] := 
      Module[{termo1, termo2, termo3}, termo1 = 0. ; termo2 = 1. ; 
        Do[termo3 = termo2 + termo1; termo1 = termo2; 
          termo2 = termo3, {i, 2, n}]; termo3]

Fibon[100]

Fibonpf[100]

Fibonacci[100]

Timing[Fib[30]]

Timing[Fibon[30]]

Timing[Fibon[1000]]

Timing[Fibonpf[10000]]

Timing[Fibonacci[10000]]