显示前N个自然数,其除数只有2、3和7。
我写了这样的东西我是口齿不清的初学者谢谢您!

defvar x 1
(defun numbers(n)
    if(mod x 2 )
    (loop for x from 1 to n
    do(print x)
    )
)
print(numbers())

最佳答案

因为我有时间,你可以看看这个可能不是完美的解决方案,但对于初学者来说应该是一个很好的起点查看“信息”选项卡中的书籍以了解语法等。

(defun divisible-by (n m)
   "Returns T if N is evenly divisible by M."
   (zerop (mod n m)))

(defun numbers (n)
   "Print all number upto N which are divisible by 2, 3 and 7."
    (loop
       for i from 1 upto N
       if (and (divisible-by i 2) (divisible-by i 3) (divisible-by i 7))
         do (format t "~D~%" i)))

07-26 09:34