Ini adalah 2 Contoh percabangan dalam Pemrograman Prolog
1. Program Menghitung Volume Balok:
go:-
write("Menghitung Volume Balok"),nl,
write("Masukkan Panjang Balok: "),read(P),
write("Masukkan Lebar Balok: "),read(L),
write("Masukkan Tinggi Balok: "),read(T),
Vol is P*L*T,
write("Volume Balok: "),write(Vol).
2. Program Menghitung Volume Kerucut:
go:-
write("Menghitung Volume Kerucut"),nl,
write("Masukkan Jari-jari: "),read(J),
write("Masukkan Tinggi Kerucut: "),read(T),
Vol is J^2*3.14*T/3,
write("Volume Kerucut: "),write(Vol).
3. Program Percabangan 1:
go:-
write("=============================="),nl,
write("Ini Menu dalam program Kami: "),nl,
write("=============================="),nl,
write("1.Menghitung Volume Balok"),nl,
write("2.Menghitung Volume Kerucut"),nl,
write("Masukkan no Pilihan anda [1-2]: "),nl,
read(X),nl,
( X=1,
write("Menghitung Volume Balok"),nl,
write("Masukkan Panjang Balok: "),read(P),
write("Masukkan Lebar Balok: "),read(L),
write("Masukkan Tinggi Balok: "),read(T),
Vol is P*L*T,
write("Volume Balok: "),write(Vol),nl,
go;
X=2,
write("Menghitung Volume Kerucut"),nl,
write("Masukkan Jari-jari: "),read(J),
write("Masukkan Tinggi Kerucut: "),read(T),
Vol is J^2*3.14*T/3,
write("Volume Kerucut: "),write(Vol);
write("No tidak tersedia!"),nl,
go
).
4. Program Percabangan 2:
%Rerata= ((UTS*30) + (UAS*40) + (Tugas*20) + (Presensi*10))/100
n:- nl,
write("*****************************"),nl,
write("Mencari Grade Nilai"),nl,
write("*****************************"),nl,
write("Masukkan UTS: "),read(UTS),
write("Masukkan UAS: "),read(UAS),
write("Masukkan Tugas: "),read(Tugas),
write("Masukkan Presensi: "),read(Pre),
Rerata is ((UTS*30) + (UAS*40) + (Tugas*20) + (Pre*10))/100,
write("Nilai UTS Kamu: "),write(UTS),nl,
write("Nilai UAS Kamu: "),write(UAS),nl,
write("Nilai Tugas Kamu: "),write(Tugas),nl,
write("Nilai Presensi Kamu: "),write(Pre),nl,
write("Nilai Rerata Kamu: "),write(Rerata),nl,
(
Rerata>=80,write("Nilai Grade Kamu A"),n;
Rerata>=65,write("Nilai Grade Kamu B"),n;
Rerata>=55,write("Nilai Grade Kamu C"),n;
Rerata>=40,write("Nilai Grade Kamu D"),n;
write("Nilai Grade Kamu E"),n
).