Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

dickbutt

(defun triangle (x)
    (if (stringp x)
        (progn
            (write-line (concatenate 'string "(triangle " (write-to-string x) ") please enter an odd integer"))
            (return-from triangle 0)
        )
    )
    (if (= (mod x 2) 0)
        (progn
            (write-line (concatenate 'string "(triangle " (write-to-string x) ") even numbers are not valid input, please enter an odd integer"))
            (return-from triangle 0)
        )
    )
    (if (< (mod x 2) 1)
        (progn
            (write-line (concatenate 'string "(triangle " (write-to-string x) ") decimal numbers are not valid input, please enter an odd integer"))
            (return-from triangle 0)
        )
    )

    (setq str "1")
    (write-line str)
    (loop for i from 1 to (+ (/ x 2) 1) do
        ;; (print (format t "~d" i))
        (setq ci (+ (* i 2) 1))
        (setq str (concatenate 'string str " " (write-to-string ci)))
        (write-line str)
    )
    (write-line "-----")
)


(triangle 7)
(triangle 9)
(triangle 23)
(triangle 2.5)
(triangle 4)
(triangle "4")

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.