0% found this document useful (0 votes)
12 views7 pages

Prolog PR Solution

Uploaded by

saw31221
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

Prolog PR Solution

Uploaded by

saw31221
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

PROLOG Programs

Total Program 6:
Questions:
Q 1.For given facts write a prolog program to find out result of Particular Student
by inputting name.

Gaurav 9.2
Anooj 8.2
chinmay 7.3
Piyush 5.7
parth 8.9
ankit 6.3
tanuja 6.2
pooja 8.2
Asmita 7.2

Program 1: -

result(gaurav, 9.2).
result(anooj, 8.2).
result(chinmay, 7.3).
result(piyush, 5.7).
result(parth, 8.9).
result(ankit, 6.3).
result(tanuja, 6.2).
result(pooja, 8.2).
result(asmita, 7.2).

getresult:-
write("Whose result do you want to know"),nl,
read(X),nl,
result(X, Y),nl,
write("this is the result"),nl,
write(Y).

Output: -
Q 2. Try to trace through the search process for given questions.

friend(jin, james).
friend(jin,john).
likes(john, jin).
likes(james, john).
happy(X):-friend(X,Y),likes(Y,X).

Question :
1. Who is happy?
2. Who is unhappy ? reason.
3. Modify the above code to make john happy

Program 2: -

friend(jin, james).
friend(jin,john).
likes(john, jin).
likes(james, john).
happy(X):-friend(X,Y),likes(Y,X).

Output:-

2/7
Q 3.Try to trace through the search process for given questions.

likes(john,jane).
likes(jane,john).
likes(jack,jane).

friends(X,Y) :- likes(X,Y), likes(Y,X).


Question :
1. Who are the Friends?

Program 3:-

likes(john,jane).
likes(jane,john).
likes(jack,jane).

friends(X,Y) :- likes(X,Y), likes(Y,X).

Output: -

3/7
Q 4. For given English statements write a prolog program.
- Facts & Rules
(1) jane is a female.
(2) john is a male.
(3) john is parent of mary.
(4) john is parent of bob.
(5) jane is parent of Mary.
(6) jane is parent of bob.
(7)bob is parent of ann.
(8)bob is parent of lisa.
(9) mary is a female.
(10) bob is a male.
- Goals.
(1) Who are the sibling.
(2) Who is mother of mary

Program 4: -

parent(john, mary).
parent(john, bob).
parent(jane, mary).
parent(jane, bob).
parent(bob, ann).
parent(bob, lisa).

male(john).
male(bob).
female(jane).
female(mary).

mother(X, Y) :- parent(X, Y), female(X).


father(X, Y) :- parent(X, Y), male(X).
sibling(X, Y) :- parent(Z, X), parent(Z, Y), X \= Y.
grandparent(X, Y) :- parent(X, Z), parent(Z, Y).

Output: -
4/7
Q 5.Write Prolog Program for Fibonacci Series.

Program 5: -

% Base cases
fib(0, 0).
fib(1, 1).

% Recursive rule
fib(N, Result) :-
N > 1,
N1 is N - 1,
N2 is N - 2,
fib(N1, F1),
fib(N2, F2),
Result is F1 + F2.

Output: -

5/7
Q 6. Write Prolog code for following FACTS.

Car Name features preferences


ferrari speed pravin
Jaguar luxury nilam
Bmw technology chirag
Mercedes comfort manasi
tesla_model_s efficiency abhishek

Program 6: -

Output:

6/7
7/7

You might also like