You are on page 1of 3

EXPERIMENT NO.

-2

AIM:-WRITE A PROGRAM FOR ADDITION OF TWO NUMBERS.

Domains
A,B,Sum=integer
Predicates
Go
clauses
go:-
write("enter the value of a= "),
readInt(A),nl,
write("Enter the value of b= "),
readInt(B),nl,
Sum=A+B,
write("Addition Sum=",Sum).

OUTPUT :-

Goal: go
enter the value of a=23
enter the value of b=78
Addition Sum=101Yes
EXPERIMENT NO :3

AIM:-WRITE A PROGRAM FOR DIVISION OF TWO NUMBERS.

Domains
A,B,X,Y,Divide=real
predicates
go
Divide(real,real)
clauses
go:-
write("enter the value of A="),
readReal(A),nl,
write("enter the value of B="),
readReal(B),nl,
Divide(A,B).
Divide(X,Y):-
Divide=X/Y,
write("The value obtained after division is=",Divide).

OUTPUT :-

GO
enter the value of A=70
enter the value of B=14
The value obtained after
division is=5Yes
EXPERIMENT NO :-4

AIM:- WRITE A PROGRAM FOR FACTORIAL OF A NUMBER.

Domains
A,B=integer
Predicates
go
fact(integer,integer)
clauses
go:-
write("enter the no:"),
readInt(A),
B=1,
fact(A,B).
fact(A,B):-
A<>1,
Z=A*B,
Y=A-1,
fact(Y,Z).
fact(1,B):-
write("factorial is=",B).

OUTPUT :-

Goal: go
enter the no:4
factorial is=43210 Yes

You might also like