Computer Science, asked by tondlekar88, 5 months ago

How to find first and last element in a list in prolog

Answers

Answered by Priyapragya
0

Answer:

domains

 list=symbol*

predicates

   last(list)

clauses

   last([X]):-

       write(\"\\nLast element is : \"),

       write(X).

   last([Y|Tail]):-

       last(Tail).

OUT PUT

=======

Goal: last([a,b,c,d,e])

Last element is : e

Yes

Explanation:

Mark me as the brainliest

Similar questions