Tuesday, 15 May 2012

Write a program in prolog to count the number of digit of a number.


domains
X,Y,A,B=integer.
predicates
digits(X,Y)
clauses
digits(X,1):-10>X,X>0.
digits(X,Y):-A=X/10,digits(A,B),Y=B+1.

1 comments

  1. Hey,

    Should use is/2 instead of =

    digits(0, 1).
    digits(X, 1) :- 10 > X, X > 0.
    digits(X, Y) :- A is (X / 10),
    digits(A, B), Y is (B + 1).

    ReplyDelete

 
© 2011-2012 ProgrammingBlue
Posts RSS Comments RSS
Back to top