Search code examples
logic

-Define a predicate to display all multiples of


i have ERROR in this code in prolog can you help me?

div(X):- X mod 3 =:= 0.

Solution

  • div(X):- X mod 3 =:= 0 ...
    div(X):- X mod 3 =:=1  ...
    

    2 mod 3 is not 0 or 1, so there is no way to do div(2), so it fails.

    Maybe you wanted

    X mod 3 =:= 0    % remainder 0
    X mod 3 =\= 0    % remainder not 0
    

    ?