Lisp programming You would need to create a code that will loop through the integer and will create a triangle with the integer provided. Again the question is "Write a lisp function triangle that takes an odd number as the argument (n) and shows a triangle of printed odd numbers as shown in the following samples. If the input is even, decimal or string, it should print an appropriate message". It should show an error for decimal numbers (which I did) and also for even number but not so sure compute that in my code.
This code works and creates a triangle but it does not do it for ONLY odd numbers. ex: 1
1 3
1 3 5
1 3 5 7
1 3 5 7 9
my code output (triangle 3):
1
12
123
(defun triangle (n)
(if (typep n'integer)
(loop for i from 1 to n
do (loop for j from 1 to i
do (write j)
)
(write-line "")
)
(write-line "Decimal numbers are not valid input, Please enter an integer"))
)
(triangle 3)
i except the out to have only odd numbers and give an error for decimal and even numbers.