Computer Science, asked by amandhanoa2211, 1 month ago

Question 3 5. (18 marks) Write PROLOG programs for the following problems: (a) Reverse a list. (b) Find the length of a list. (c) Find the average of a list of numbers.​

Answers

Answered by singhtejashvin
0

Answer:

right answer is a (a) optoin

Answered by shilpa85475
0

PROLOG PROGRAM

b. domains

  list=symbol*    

predicates

  len(list)

  findlen(list,integer)    

clauses

  len(X):-

      findlen(X,Count),

      write("\nLength Of List : "),

      write(Count).

  findlen([],X):-

      X=0.

 

  findlen([X|Tail],Count):-

      findlen(Tail,Prev),

      Count = Prev + 1.

       

a.domains

  list=symbol*

predicates

  rev(list)

  findrev(list,list,list)

clauses

  rev(L):-

      findrev(L,[],List2),

      write(\"\\nReverse Of Given List : \",List2).

  findrev([],List1,List1).

  findrev([X|Tail],List1,List2):-

      findrev(Tail,[X|List1],List2).

Similar questions