well you can either use any way to get simple arithmatics in prolog. 
For example typing X is 3+2.
gives X=5.
in prolog .
Similarly you can write R is 5*2.
it will give R= 10.
so doing simple arithmatics is very simple.
please note that X or R is capital it can not be a lowercase character otherwise prolog will give output as true.
or use this knowledge base
.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!copy from below!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sum:-
write_ln('Enter the first number:-'),
read(First),
write_ln('Enter second number:-'),
read(Second),
S is First+Second,
write('sum of '),write(First),write('and '),write(Second),write('is ='),write(S).
.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!copy from below!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sum:-
write_ln('Enter the first number:-'),
read(First),
write_ln('Enter second number:-'),
read(Second),
S is First+Second,
write('sum of '),write(First),write('and '),write(Second),write('is ='),write(S).
sub:-
    write_ln('Enter the first number:-'),
    read(First),
    write_ln('Enter second number:-'),
    read(Second),
    S is First-Second,
     write(' difference  of '),write(First),write(' and '),write(Second),write(' is ='),write(S).
multiply:-
    write_ln('Enter the first number:-'),
    read(First),
    write_ln('Enter second number:-'),
    read(Second),
    S is First*Second,
     write('Multiplication of '),write(First),write(' and '),write(Second),write(' is ='),write(S).
divison:-
    write_ln('Enter the first number:-'),
    read(First),
    write_ln('Enter second number:-'),
    read(Second),
    S is First/Second,
     write('Divison '),write(First),write(' / '),write(Second),write(' is ='),write(S).

Comments
Post a Comment
share your thoughts ....