21.Write a Prolog program to implement delete_nth (N, L, R) that removes the element on Nth position from a list L to generate a list R.
%Prolog program to implement delete_nth (N, L, R)
% below delete_nth function is not predefined you can use any name as function
delete_nth(1, [H|T], T).
delete_nth(N, [H|T], [H|R]):- N1 is N-1,
delete_nth(N1, T, R).
% Output
No comments:
Post a Comment