+..Welcome..+

Welcome to our mathematic final project blog. We are from discrete math project group. and we are so sorry for Mr.Ahmad Mukhlason because our blog is not complete yet and we just add a category for the final project. But we have done it last deadline.
Thanks for all.

Selasa, 08 Desember 2009

Input and Output in Prolog

Input and Output in Prolog

- Question 1

A Possible definition using recursion is given below:
outsquare(N1,N2):-N1>N2. outsquare(N1,N2):-
write(N1),write(' squared is '),Square is N1*N1, //menyatakan bahwa setelah 'squared is' akan menampilkan jumlah dari N1 pangkat 2
write(Square),nl,M is N1+1,outsquare(M,N2).

so if we execute in prolog :


















-Question 2

The following definition uses the repeat predicate :
go:-repeat,get0(X),getrest(X). getrest(13):-nl. /* newline */ getrest(63):-nl,repeat,get0(X),X=:=13. getrest(X):-put(X),fail.

if we execute in prolog:
















-Question 3

The following program uses backtracking with failure :

find:- person(_,_,Age,_,Prof),Age>40, write(' Profession is '),write(Prof),nl,fail. find. person(kazama,ren,45,okinawa,musician). person(aoi,sora,33,okaido,actress). person(henry,smith,26,manchester,plumber). person(bambang,pamungkas,62,indonesia,player). person(yankumi,yoshioka,29,saitama,teacher).

if we execute in prolog:
















-DoNe-

1 komentar: