Assignment 1
1.Write a program in PROLOG to perform all arithmetic operations in prolog.
sum(X,Y,Result):-
X>0, Y>0,
Result is X+Y.
sum(X,Y,Result):-
X>0, Y>0,
Result is X-Y.
sum(X,Y,Result):-
X>0, Y>0,
Result is X*Y.
sum(X,Y,Result):-
X>0, Y>0,
Result is X/Y.
2. Write a program in PROLOG to find the factorial of a number.
fact1(0,Result) :-
Result is 1.
fact1(N,Result) :-
N > 0,
N1 is N-1,
fact1(N1,Result1), Result is Result1*N.
3. Write a program in PROLOG to calculate the area of circle, triangle and square.
area_circle(R,Result):-
R>0,
Result is R*R*3.14.
area_triangle(B,H,Result):-
B>0,H>0,
Result is 0.5* H*B.
4. Write a program in PROLOG to find even or odd number.
even(X):-(X mod 2=:=0->write('even');write('odd')).
5. Write a program in PROLOG to find maximum of two number.
max(X,Y,Z):-X<Y,write(number,Y).