Contoh Program Sederhana Prolog


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).



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).

 
















Prolog Rumus Matematik

menu :-
write('-------MENU-------'),nl,
write('1. Luas Segitiga'),nl,
write('2. Volume Balok'),nl,
write('3. Volume Kubus'),nl,
write('4. EXIT'),nl,
write('Masukkan pilihan : '), read(PIL), nl,

(PIL=1,nl,
write('Luas Segitiga'),nl,
write('Masukkan Alas : '),read(A),nl,
write('Masukkan Tinggi : '),read(T),nl,
L is A*T/2,
write('LUAS SEGITIGA : '),write(L),nl,

menu;
PIL=2,nl,
write('Volume Balok'),nl,
write('Masukkan Panjang : '),read(P),nl,
write('Masukkan Lebar : '),read(L),nl,
write('Masukkan Tinggi : '),read(T),nl,
V is P*L*T,
write('VOLUME BALOK : '),write(V),nl,

menu;
PIL=3,nl,
write('Volume Kubus'),nl,
write('Masukkan Sisi : '),read(S),nl,
V is S*S,
write('VOLUME KUBUS : '),write(V),nl,

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


=========================================================
* contoh-contoh program kondisi pada prolog :
depan(A, A) :- A < 10.
depan(A, B) :-
A1 is A // 10,
depan(A1, B1),
B is B1.


output :
Input : ?- depan(256, X).
Output : Yes. X = 2.

^ Contoh lain :
kondisi:-nl,
write(‘masukkan berat badan anda :’),read(R),nl,
X if R>40->
write(‘ideal’);
write(‘kurang ideal’).



Sumber :
http://rachmatkull.blogspot.com/2010/10/prolog-lp.html







Read Users' Comments (1)Comment

1 Response to "Contoh Program Sederhana Prolog"