Advertisement
Dr4noel

LOGICA: TIPURI DE EXERCITII

Dec 6th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.37 KB | None | 0 0
  1. % Author:
  2. % Date: 12/6/2017
  3.  
  4. ec(A,B,C) :-D is B*B - 4 *A * C,D < 0, write("Nu are solutii").
  5. ec(A,B,C) :-D is B*B - 4 * A * C,D = 0, X1 is (-B)/(2*A), write(X1).
  6. ec(A,B,C) :- D is B*B - 4*A*C,D > 0, X1 is ((-B) + sqrt(D))/(2*A),
  7.                 X2 is ((-B)-sqrt(D))/(2*A), write("X1="),write(X1),
  8.                 write("X2="),write(X2).
  9.                
  10. suma(1,1).
  11. suma(N,F) :- N>0, N1 is N-1, suma(N1,F1),F is 1/N + F1.
  12. ackerman(0,N,R):-R is N+1, N > 0.
  13. ackerman(M,0,R):-M1 is M-1,ac(M1,1,R),M > 0.
  14. ackerman(M,N,R):- M1 is M - 1, N1 is N-1, ac(M,N1,R1), ac(M1,R1,R), M > 0, N > 0.
  15.  
  16.  
  17.  
  18. factorial(0,1).
  19. factorial(N,F) :- N>0, N1 is N-1, factorial(N1,F1), F is N * F1.
  20. ff(M,N,R) :- N < M, factorial(N,F), R is M * F .
  21. ff(M,N,R) :- N >= M, R is N- M.
  22.  
  23.  
  24. pow(_,0,R):-R is 1.
  25. pow(N,M,R):-M>0,M1 is M-1,pow(N,M1,R1),R is R1*N.
  26. f(M,N,R) :- N < M, pow(N,M,R).
  27. f(M,N,R) :- N >=M, R is M* N.
  28.  
  29.     %CATE NUMARE POZITIVE SE GASESC INTR-O LISTA
  30. poz([],0).
  31. poz([P|Rest], Poz) :- P >= 0, poz(Rest,P1), Poz is P1 + 1.
  32. poz([P|Rest], Poz) :- P < 0, poz(Rest,Poz).
  33.  
  34. nr([_P|Rest],Poz) :- nr(Rest,P1), Poz is P1+1.
  35. nr([],0).
  36. compar(L1,L2) :- nr(L1,Rez1), nr(L2,Rez2), Rez1>Rez2, write("Prima lista este mai mare").
  37. compar(L1,L2) :- nr(L1,Rez1), nr(L2,Rez2), Rez1<Rez2, write("A doua lista este mai mare").
  38. compar(L1,L2) :- nr(L1,Rez1), nr(L2,Rez2), Rez1=Rez2, write("Cele 2 liste sunt egale").
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement