Assignment (Practical)
Assignment (Practical)
#Source Code:
Output:
Teacher’s Signature
#Source Code:
Output:
Teacher’s Signature
#Source Code:
fact(0, 1).
fact(N, R):- N>0, N1 is N-1, fact(N1, F1), R is N*F1.
Output:
Teacher’s Signature
#Source Code:
fibo(1, 0).
fibo(2, 1).
fibo(N, R):- N>2, N1 is N-1, N2 is N-2, fibo(N1, R1), fibo(N2, R2), R is R1+R2.
Output:
Teacher’s Signature
#Source Code:
Output:
Teacher’s Signature
#Source Code:
Output:
Teacher’s Signature
#Source Code:
Output:
Teacher’s Signature
#Source Code:
Output:
Teacher’s Signature
#Source Code:
Output:
Teacher’s Signature
#Source Code:
max(X, Y, X) :- X >= Y.
max(X, Y, Y) :- X < Y.
Output:
Teacher’s Signature
#Source Code:
maxlist([X], X).
maxlist([X|Xs], Max) :- maxlist(Xs, MaxXs), max(X, MaxXs, Max).
Output:
Teacher’s Signature
#Source Code:
Output:
Teacher’s Signature
#Source Code:
evenlength([]).
evenlength([_|Xs]) :- oddlength(Xs).
oddlength([_]).
oddlength([_|Xs]) :- evenlength(Xs).
Output:
Teacher’s Signature
#Source Code:
Output:
Teacher’s Signature
#Source Code:
maxlist([X], X).
maxlist([X|Xs], Max) :- maxlist(Xs, Y), (X > Y -> Max = X ; Max = Y),!.
Output:
Teacher’s Signature
#Source Code:
Output:
Teacher’s Signature