List in Prolog

It is important for any programming tool to have some functionality of handling collections like array, list or something else. Prolog use lists for the very purpose and I must warn C/C++ programmers (or even Java, C# or any other C-like language fan) that lists are not arrays but similar to it. A list must … Continue reading List in Prolog

Advertisements

Prolog program to find GCDs and LCMs

The least common multiple (LCM) of two integers a, b is the smallest positive integer that is a multiple of both a and b. Despite of the fact, there exist several formulas to calculate the LCM of two integers, most popular formula, especially to the programmers, is by using GCD of the two: LCM(a, b) … Continue reading Prolog program to find GCDs and LCMs

Prolog program to Calculate factorial of N

We know the formula for calculating n! (factorial of n)  is: n! = n * (n-1)! We can interpret this simple mathematical equation into a Prolog program. To do so, we must determine the basis of the recursion, 0! = 1 We will use two predicates here, factorial predicate with one argument N, that will … Continue reading Prolog program to Calculate factorial of N