Bananaware

prologs

Aug 22nd, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.49 KB | None | 0 0
  1. /* fatorial recursivo */
  2. fatorial(1,1) :- !.
  3. fatorial(N,F):- X is N-1,
  4.                 fatorial(X, Y),
  5.                 F is N*Y,
  6.                 !.
  7.  
  8.  
  9. /* exercício 1 - fibonacci */
  10. fib(1,0) :- !.
  11. fib(2,1) :- !.
  12. fib(N,F) :- X is N-1,
  13.             Y is N-2,
  14.             fib(X,A),
  15.             fib(Y,B),
  16.             F is A+B,
  17.             !.
  18.  
  19.  
  20. /* exercício 2 - número natural */
  21. nat(X) :- positivo(X),
  22.           A is round(X),
  23.           A =:= X.
  24.          
  25. positivo(X) :- X > 0.
Advertisement
Add Comment
Please, Sign In to add comment