J
J
JustQuantor2021-02-07 16:49:38
Prolog
JustQuantor, 2021-02-07 16:49:38

Prolog. How to multiply two numbers by recursion?

I found this code, which seems to solve the problem, but when it is called, an error is generated. Perhaps I'm not calling it correctly? I hope for your help.

add(0,X,X).
add(s(X),Y,Z):-add(X,s(Y),Z).

mult(0,X,0).
mult(s(X),Y,Z):-mult(X,Y,A), add(Y,A,Z).

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question