Question: Prolog language Write a predicate which processes a list of numbers by adding up every second number. The predicate is to work as shown below.
Prolog language
Write a predicate which processes a list of numbers by adding up every second number. The predicate is to work as shown below. (Note that you are not asked to check the input to be a valid list of numbers but can simply assume that your predicate always receive list of numbers).
?- addSecond([1,3,5,4],S). S = 7. ?- addSecond([1,3,5],S). S = 3. ?- addSecond([1,3],S). S = 3. ?- addSecond([1],S). S = 0. ?- addSecond([1,3,5],3). true.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
