Created
December 14, 2012 16:01
-
-
Save trietptm/4286485 to your computer and use it in GitHub Desktop.
Sum of digits of a number (in PROLOG)
a simple snippet to find the sum of digits of a given number in PROLOG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sumofdigits(X, X) :- X<10. | |
sumofdigits(X, Y) :- X>=10, X1 is X // 10, X2 is X mod 10, sumofdigits(X1, Y1), Y is Y1 + X2. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank man!
this one sure helped me...