In: Computer Science
*LISP PROGRAM*
2. Write a function that, given a list of lists, returns the total length of all the lists. This problem can be solved two different ways.
3. Write a program that prompts the user to enter two numbers and then outputs the sum of the two numbers.
4.Write ALLODDP, a recursive function that returns T if all the numbers in a list are odd.
2. Write a function that, given a list of lists, returns the total length of all the lists. This problem can be solved two different ways.
(defun totalLength(mylist)
(setq total 0)
(loop
(setq total (+ total (length (car
mylist))))
(setf mylist (cdr mylist))
(if (endp mylist) (return))
)
total
)
(format t "~%Total length of list: ~s ~%~%" (totalLength '((a) (a b) (a b c))))
output
3. Write a program that prompts the user to enter two numbers and then outputs the sum of the two numbers.
(write-line "Enter first number")
(setq number1 (read))
(write-line "Enter second number")
(setq number2 (read))
(setq total (+ number1 number2))
(format t "~%~s+~s=~s ~%" number1 number2 total)
output
Completed 2 questions. For the answer of last question post a new post with only that question.