Ask Your Question
1

What is the LISP code to display the even numbers from a sequence of 10 values?

asked 2022-05-06 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-02-10 05:00:00 +0000

bukephalos gravatar image

Here's one way to display the even numbers from a sequence of 10 values in LISP:

(let ((numbers '(1 2 3 4 5 6 7 8 9 10)))
  (dolist (num numbers)
    (when (evenp num)
      (print num))))

This code starts by defining a variable called numbers and assigning it a list of integers from 1 to 10. Then, it uses the dolist function to iterate over each element in the list. For each element, it checks if it's even using the evenp function. If it is, it prints the number to the console using print.

This code should output the even numbers:

2
4
6
8
10
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-06 11:00:00 +0000

Seen: 1 times

Last updated: Feb 10 '23