Showing posts with label prolog. Show all posts
Showing posts with label prolog. Show all posts

Friday, 14 June 2024

Contoh Lain dari contoh percabangan dengan penambahan syarat

 Contoh Lain dari Contoh percabangan dengan penambahan syarat


Gambar Output

/*catatan
 * jika BMI dan Usia>=40 munculkan pesan "Obesitas II" dan "Awas Bahaya"
 * dll
 */


mulai:-
    write("Masukkan Berat Badan: "),read(BB),
    write("Masukkan Tinggi Badan: "),read(TB),
    write("Masukkan Usia: "),read(Usia),
    
    BMI is BB/((TB/100)*(TB/100)),
    
    write("Berat Badan: "),write(BB),nl,
    write("Tinggi Badan: "),write(TB),nl,
    write("Usia: "),write(Usia),nl,
    write("BMI: "),write(BMI),nl,
    (
        BMI>=30,Usia>=40,write("Obesitas II"),write(", Awas Bahaya");
        BMI>=30,Usia<40,write("Obesitas II"),write(", Lakukan Diet!");
        BMI>=25,Usia>=40,write("Obesitas I"),write(", Hati-Hati");
        BMI>=25,Usia<40,write("Obesitas I"),write(", Kurangi Lemak");
        BMI>=23,Usia>=40,write("Berlebih"),write(", Waspada");
        BMI>=23,Usia<40,write("Berlebih"),write(", Banyakin Olah Raga");
        BMI>=18.5,Usia>=40,write("Normal"),write(", Pertahankan");
        BMI>=18.5,Usia<40,write("Normal"),write(", Tetap Imbangi dengan olah raga");
        BMI<18.5,Usia>=40,write("Kurang"),write(", Tingkatkan Nutrisi");
        BMI<18.5,Usia<40,write("Kurang"),write(", Tingkatkan BB Anda");
        mulai
    )
    .

Thursday, 6 June 2024

2 Contoh percabangan dalam Pemrograman Prolog

 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

    ).

Thursday, 9 May 2019

Simple Dinamic Programming in Prolog

Hai...how are you?
Remember in Simple Programming In Prolog
We can make a simple programming in prolog  more dymanic. This program used  two Predikat Built-In, write( ) and read ( ). The purpose of making this program is to involve users in the calculation process, attention to the this program:

%fact
 
% rule
start:- write('This is a Simple Program in Prolog'),nl,
          write('Enter length of Rectangular: '),read(L),
          write('Enter width of Rectangular: '),read(W),
          Rectangular_Area is W*L,
          write('Length of rectangular Entered: '),write(L),nl,
          write('Width of Rectangular Entered: '),write(W),nl,
          write('Rectangular Area: '),write(Rectangular_Area).