).
2.Factorial of Number:
Code:
fact(0,1).
fact(N,F):-
(
).
Output:
7.Implement Concatenation:
Code:
conc([],L,L).
conc([X|M],N,[X|Q]):-
conc(M,N,Q).
Output:
8.Implement Palindrome:
Code:
palind([]):- write('palindrome').
palind([_]):- write('palindrome').
palind(L) :-
append([H|T], [H], L),
palind(T)
;
write('Not a palindrome').
Output:
9.Implement maxlist(List,Max):
Code:
maxlist([H|T],R):-
length(T,L),
L>0 ->
(
maxlist(T,R1),
(
H > R1 ->
R is H
;
R is R1
)
)
;
R is H.
Output:
10.Implement Sumlist(List,Max):
Code:
sumlist([],0).
sumlist([H|T],R):-
sumlist(T,R1),
R is H+R1.
Output:
R is H
)
;
R is H.
Output:
12.Implement the cut predicate:
Code:
max(X,Y,X):-X>=Y,!.
max(X,Y,Y):-X<Y.
Output: