Sie sind auf Seite 1von 9

//PROGRAM OF GREATER NUMBER

predicates
go

clauses

go:-
write("enter two numbers"),nl,
readint(A),
readint(B),
A>B,
write("Ist is greater"),nl.

go:-
write("2nd is greater"),nl.

//OUTPUT

Goal: go
enter two numbers
12
10
Ist is greater
Yes
Goal: go
enter two numbers
30
40
2nd is greater
Yes

//PROGRAM OF QUADRATIC EQUATION:-


domains
A,B,C,D=real
predicates
go
test(A,B,C,D)

clauses
go:-
write("enter a quadratic equation"),
readint(A),
Readint(B),
readint(C),
write(A,"x2+",B,"x+",C),nl,
D=B*B-4*A*C,
write("D=",D),
D>0,
Write("roots are REAL"),
test(A,B,C,D).

go:-
Write("roots are imaginary").

test(A,B,C,D):-
D1=Sqrt(D),
R1=(-B+D1)/2*A,
R2=(-B-D1)/2*A,nl,
Write("roots are:R1=",R1),nl,
Write("R2=",R2).

**** OUTPUT*****

Goal: go
enter a quadratic equati
on
4
5
6
4x2+5x+6
D=-71
roots are imaginary
Yes

//PROGRAM OF RECURSION

domains
Rec=integer

predicates
count(Rec)

clauses
count(12).
count(Rec):-
Rec<12,
Write(Rec," "),
N=Rec+1,
count(N).
count(Z):-
write("your value is :",Z),nl,
write("value must be less than 12"),nl.

****** OUTPUT*****

Goal: count(13)
your value is :13
value must be less than
12
Yes

Goal: count(7)
7 8 9 10 11
Yes

//PROGRAM OF WATER JUG

domains
X,Y=integer
predicates
start
water(integer,integer)

clauses
start:-
Write("Enter the quantity of 4G jug(max quantity=4)="),
readint(X),
X<=4,
write("enter the quantity of 3g jug(max quantity=3)="),
readint(Y),
Y<=3,
write("qunatity of both jugs are:"),
write(" (",X," ",Y,")"),nl,
water(X,Y).

water(2,0):-
Write("(2,0)"),nl,
write("goal achieved"),nl.

water(0,2):-
Write("(0,2)"),nl,
water(2,0).

water(0,0):-
Write("(0,0)"),nl,
water(0,3).

water(0,3):-
write("(0,3)"),nl,
water(3,0).

water(3,0):-
write("(3,0)"),nl,
water(3,3).

water(3,3):-
write("(3,3)"),nl,
water(4,2).

water(D,2):-
write("(",D,",2)"),nl,
water(0,2).

water(3,1):-
write("(3,1)"),nl,
water(4,0).

water(4,0):-
write("(4,0)"),nl,
water(0,0).

water(2,D):-
write("(2,",D,")"),nl,
water(2,0).
water(C,3):-
Write("(",C,",3)"),nl,
water(0,3).

water(1,1):-
write("(1,1)"),nl,
water(2,0).

******* OUTPUT*******

Goal: start
Enter the quantity of 4G
jug(max quantity=4)=3
enter the quantity of 3g
jug(max quantity=3)=3
qunatity of both jugs ar
e: (3 3)
(3,3)
(4,2)
(0,2)
(2,0)
goal achieved
Yes

//PROGRAM OF LOGON

domains
name,password=symbol

predicates
login
userinput(name,password)
getinput(name,password)

clauses

login:-
getinput(_,_),
write("login permitted"),nl.

login:-
write("login not permitted"),nl.

getinput(name,password):-
write("enter name"),nl,
readln(N),
Write("enter password"),nl,
readln(P),
userinput(N,P).

userinput(sonu,abcd).
userinput(c,d).
//OUTPUT

Goal: login
enter name
isha
enter password
1234567
login not permitted
Yes

Goal: login
enter name
sonu
enter password
abcd
login permitted
Yes

//program of upper to lower ‘n’ lower to upper string

predicates
capital
clauses
capital:-
write("enter string 1"),nl,
Readln(A),
Upper_Lower(A,B),
write(B),nl,
write("enter string 2"),nl,
Readln(D),
Upper_Lower(C,D),
write(C),nl.

//output

Goal: capital
enter string 1
WELCOME
welcome
enter string 2
welcome
WELCOME
Yes

//program of string

domains
X,Y,A,B=string
C=integer
predicates
start
string(integer)

clauses
start:-
write("enter your choice"),nl,
write("1.concatenation",
"2.front token",
"3. front char",
"4.front string",
"5.string length"),nl,
readint(C),
string(C).

string(1):-
X="hello",
Y=" hv a nice day",
write(X),nl,
write(Y),nl,
write("after concatination string is:"),nl,
concat(X,Y,OUTPUT),
write(OUTPUT),nl.

string(2):-
X="hv a nice day",
write(X),nl,
write("front token is:"),nl,
fronttoken(X,A,B),
write(A),nl,
write("remaining string is:"),nl,
write(B),nl.

string(3):-
X="hv a nice day",
frontchar(X,A,B),
write("front character is:"),nl,
write(A),nl,
write("remaining string is:"),nl,
write(B),nl.

string(4):-
X="hello",
write(X),nl,
frontstr(4,X,A,B),
write("front string is:"),nl,
write(A),nl,
write("remaining string is:"),nl,
write(B),nl.

string(5):-
X="hello",
write(X),nl,
write("string length is:"),nl,
str_len(X,L),
write(L).
//output

Goal: start
enter your choice
1.concatenation
2.front token
3.front char
4.front string
5.string length

1
hello
hv a nice day
after concatination string is:
hello hv a nice day

2
hv a nice day
front token is:
hv
remaining string is:
a nice day

3
front character is:
h
remaining string is:
v a nice day

4
hello
front string is:
hell
remaining string is:
o

5
hello
string length is:
5
Yes

//program of compound predicates

domains
location=address(Street,City,State)
Street,State,City=String

predicates

person(String,Symbol,Location)
go

clauses
go:-
person("jack",engineer,address(_,_,X)),
person(Name,engineer,address(_,_,X)),
write(Name),nl.

person("tom",engineer,address("xyz","b.garh","and")).
person("mary",engineer,address("xyz","b.garh","or")).
person("jack",engineer,address("xyz","b.garh","and")).

//output

Goal: go
tom
Yes

//PROGRAM OF FAIL PREDICATE

predicates
go
person(Symbol,Symbol)

clauses
go:-
person(Name,Design),
Write(Name),nl,
Write(Design),nl,
fail.

person(raman,manager).
person(rajiv,tl).
person(kamal,sa).

//OUTPUT

Goal: go
raman manager
rajiv tl
kamal sa
No

//PROGRAM OF LIST

domains
namelist=names*
names=symbol

predicates
club(namelist)
Writelist(namelist)
clauses

Writelist([Head|Tail]):-
write(Head),nl,
writelist(Tail).
club([ab,ac,ad,ae]).

//OUTPUT

Goal: Writelist([a,b,c,d])
a
b
c
d
No

//PROGRAM OF LIST
domains
namelist=names*
names=symbol

predicates
club(namelist)

clauses
club([a,b,c,d]).

//OUTPUT

Goal: club([A|B])
A=a, B=["b","c","d"]
1 Solution
Goal: club([A,B|C])
A=a, B=b, C=["c","d"]
1 Solution

Das könnte Ihnen auch gefallen