Senin, 07 Desember 2009

LOOPS

LOOPS
The Answer of Exercise 6


1. if we want to define the values of the squares of the integers from N1 to N2 inclusive and test it with N1 = 6 and N2 = 12. So, first we must write the rule or program in notepad. we can use writesquares to find the value of its squares.In our program, we change N1 to A, and N2 to B (but it's not problem).
then, You can see the rule in the picture below:




So, the result will be shown on our SWI Prolog if we write writesquares(6,12). on our SWI Prolog. Lets see the picture below:


2. If we want to define and test a predicate to read in a series of characters input by the user and output all of those before the first new line or ? character. So, first we must write the rule or program in notepad. we can use this rule to solve this problem. You can see the rule in the picture below:


then, the result will be shown if we write go., and then we can write anyword that we want, for the example; we write MatdisHolic on our SWI Prolog. Lets see the picture below:



3. if we want to find the professions of all those in data which have age over 40, So, for the first we must write the rule or program in notepad. we can use rule like in example 6.3.1 to solve this problem. You can see the rule in the picture below:

Notes: we can change "allover40" to other word that we want because its can't make the result will be error.

then, the result will be shown in our SWI Prolog if we write "allover40." before. Lets see the picture below:

1 komentar: