Studi Kasus : PROLOG

12.1 Membahas Contoh Program



Prolog Perulangan Segitiga Bintang

loopa(A,B):-
(A>0,
loopb(B),nl,
C is A-1,
D is B+1,
loopa(C,D);
A=0,nl).

loopb(D):-
( D>0,write('*'),
B is D-1,
loopb(B);
D=0,write('')).
menu :-
write('-------MENU-------'),nl,
write('1. Biodata'),nl,
write('2. Segitiga'),nl,
write('3. Keluar'),nl,
write('Masukkan pilihan : '), read(PIL), nl,

(PIL=1,nl,
write('------BIODATA------'),nl,
write('Nama saya : '),read(A),nl,
write('NPM saya : '),read(B),nl,
write('-------------------'),nl,
write('Nama saya : '),write(A),nl,
write('NPM saya : '),write(B),nl,

menu;
PIL=2,nl,
write('Nilai perulangan : '),read(A),loopa(A,1),

menu;
PIL=3,nl,
write('Makasih'),nl).

12.2 Membuat Program Sederhana 




Prolog Perulangan Segitiga Angka

loopa(A,B):-
(A>0,
loopb(B,1),nl,
C is A-1,
D is B+1,
loopa(C,D);
A=0,nl).

loopb(X,Z):-
( X>0,write(Z),
Y is X-1,
W is Z+1,
loopb(Y,W);
X=0,write('')).
menu :-
write('-------MENU-------'),nl,
write('1. Biodata'),nl,
write('2. Segitiga'),nl,
write('3. Keluar'),nl,
write('Masukkan pilihan : '), read(PIL), nl,

(PIL=1,nl,
write('------BIODATA------'),nl,
write('Nama saya : '),read(A),nl,
write('NPM saya : '),read(B),nl,
write('-------------------'),nl,
write('Nama saya : '),write(A),nl,
write('NPM saya : '),write(B),nl,

menu;
PIL=2,nl,
write('Nilai perulangan : '),read(A),loopa(A,1),

menu;
PIL=3,nl,
write('Makasih'),nl).


sumber bab 9-12:

http://sulimah-mhiyu.blogspot.co.id/2010/11/contoh-program-sederhana-prolog.html
http://soddis.blogspot.co.id/2014/01/dasar-dasar-prolog.html
http://ryanstiawanlagi.blogspot.co.id/2016/01/dasar-dasar-prolog-dan-struktur-prolog.html
http://pipittahta.blogspot.co.id/2015/06/pr.html

Komentar

Postingan populer dari blog ini

REPRESENTASI PENGETAHUAN

Contoh Generate and Test

Metode Pencarian dan Pelacakan 2 (Heuristik)