thread527-35971: prolog: print list with sequence numbers of elements
display_list([]).
display_list([X|R]):-
Y is 0,
Y1 is Y+1,write(Y1),write(' '),
write(X),nl,display_list1(R,Y1).
display_list1([],_).
display_list1([X|R],X1):-
X2 is X1+1,
write(X2),write(' '),
write(X), nl, display_list1(R,X2).
Red Flag Submitted
Thank you for helping keep Eng-Tips Forums free from inappropriate posts. The Eng-Tips staff will check this out and take appropriate action.
Reply To This Thread
Posting in the Eng-Tips forums is a member-only feature.
As the cloud is increasingly adopted for product development, questions remain as to just how cloud software tools compare to on-premise solutions. Download Now
Engineering-centric businesses face a number of challenges today, but unmanageable design and change processes don’t need to be counted among them. Download Now