Advertisement
steffffffan

P2_7

Nov 20th, 2022
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.47 KB | None | 0 0
  1. %7.
  2. %a) Definiti un predicat care determina produsul unui numar reprezentat
  3. % cifra cu cifra intr-o lista cu o anumita cifra. De ex: [1 9 3 5 9 9] * 2
  4. %=> [3 8 7 1 9 8]
  5.  
  6. lmulh([],_,[],0):-!.
  7. lmulh(_,0,[0],0):-!.
  8. lmulh([H],B,[R],C):- !, R is (H*B) mod 10, C is (H*B) // 10.
  9. lmulh([H|T],B,R,C):-
  10.     lmulh(T,B,R1,C1),
  11.     P is H*B+C1,
  12.     HR is P mod 10,
  13.     C is P//10,
  14.     R = [HR|R1].
  15.  
  16. lmul(A,B,R):- lmulh(A,B,R,0).
  17. lmul(A,B,R):- lmulh(A,B,R1,C), C\=0, R=[C|R1].
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement