Operator and Arithmatic part2

Now, we continue our studying with Arithmetic Operator using Prolog. As we know that there are some operators we can use in arithmetic, for example +, -, /, *, etc. For more information about this operator, you can see it in TUTORIAL category and title OPERATOR AND ARITHMETIC (Summary).

For application of this operator, see the question below :

With a predicates that consists of two arguments, both numbers, please calculate

a. Their average

b. The square root of their product

c. The larger of those number

1. To answer it, open your prolog and then create new file namely part.pl

2. Write a rule as follow :

Notes :

average(X,Y,Average) :- Average is (X/Y)/2.

Means that to calculate the average, we use formula as : Average = (X+Y)/2

square_root(X,Y,Square_root):- Square_root is sqrt(X*Y).

means that to calculate the square root of two product numbers, we use formula :

Square_root = sqrt(X*Y)

result :

3. Consult part2.pl, write number(10,20).

you can change 4 and 5 with other numbers.

4. Press Enter


just try it my friends..
good luck..
do the best...
  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

0 Response to "Operator and Arithmatic part2"

Posting Komentar