next up previous
Next: Full Prolog Up: Arithmetic in Prolog Previous: length/2

Exercises

Define predicate square/2 that takes a number as its first argument and returns the square of that number as its second argument. (No recursion in this one.)

Define a predicate power/3 that takes numbers as its first two arguments P and N and returns as the value of its third argument a number which is N to the power of P. E.g.
|?- power(3,2,P).

P = 8 

yes
Note that this requires a recursive rule and the use of arithmetic.



Steve Harlow 2001-11-26