Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %somatorio
- somatorio(1,1).
- somatorio(N,S):- N1 is N-1,somatorio(N1,S1), S is S1+N.
- %factorial
- factorial(0,1).
- factorial(N,S):- N1 is N-1,factorial(N1,S1), S is S1*N.
- %comprimento
- comprimento([],0).
- comprimento([_|Cauda],S):-comprimento(Cauda,S1),S is S1+1.
- n_elemento(1,[C|_],C).
- n_elemento(X,[_|Cauda],N):-X1 is X-1,n_elemento(X1,Cauda,N).
- potencia(B,1,B).
- potencia(B,N,P):-N1 is N-1,potencia(B,N1,P1),P is P1*B.
- %max(X,Y,Max):-X>Y -> Max is X ; Max is Y.
- %OU
- max(X,Y,X):-X>=Y,!.
- max(_,Y,Y).
- %maxlista([C],C).
- %maxlista([C|Cauda],X):-maxlista(Cauda,X1),C>X1 -> X is C ; X is X1.
- %OU
- maxlista([C],C):-!.
- maxlista([C|Cauda],X):-maxlista(Cauda,X1),max(C,X1,X).
Add Comment
Please, Sign In to add comment