20_09

Write a prolog program, insert_nth(item, n, into_list, result) that asserts that result is the list into_list with item inserted as the n‘th element into every list at all levels.

 Source Code :

 

mem(X,[X|_]).

mem(X,[_|T]):- mem(X,T).

insert(L,[_X|_Y],[L|_]).

insert(L,P,[X|Y],[X|M]):-

 P>1,

 P1 is P-1,

 insert(L,P1,Y,M).

insert(L,1,[X|Y],M):- append([L],[X|Y],M).

 

Output :

Write a prolog program, insert_nth(item, n, into_list, result) that asserts that result is the list into_list with item inserted as the n‘th element into every list at all levels


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...