6. Write a Prolog program to remove the Nth item from a list.
del(1,[_|T],T).
del(P,[X|Y],[X|R]):-
P1 is P-1,
del(P1,Y,R).
OUTPUT:
del(2,[1,2],X).
X = [1]
Next101001,000 Stop
del(3,[1,2,3,4],X).
X = [1, 2, 4]
Next101001,000 Stop
del(5,[1,2,3,4],X).
false
No comments:
Post a Comment