sum(X,Y):-Z is X+Y,
write('Sum of two numbers is '),write(Z).
minus(X,Y):-X>Y,Z is X-Y,
write('Subtraction of two numbers is '),write(Z);
X<Y,Z is Y-X,
write('Subtraction of two numbers is '),write(Z).
mul(X,Y):-Z is X*Y,
write('Multiplication of two numbers is '),write(Z).
div(X,Y):-Y=0,write('Denominator should not be zero');
Z is X/Y,
write('Sum of two numbers is '),write(Z).
Output
1 ?- sum(7,8).
Sum of two numbers is 15
true.
2 ?- minus(22,3).
Subtraction of two numbers is 19
true .
3 ?- minus(22,33).
Subtraction of two numbers is 11
true.
4 ?- mul(3,6).
Multiplication of two numbers is 18
true.
5 ?- div(4,2).
Sum of two numbers is 2
true.
6 ?- div(4,0).
Denominator should not be zero
true .
7 ?- div(42,11).
Sum of two numbers is 3.8181818181818183
true.
0 comments:
Post a Comment