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

Sin - Cos - Calculator

(defun sin-cos-comp (x n)
    (if (and (integerp x) (integerp n))
        (if (oddp n)
            (if (and (< -10 x) (< x 10))
                (print (series x n 1 2 0))
                (print "X has to be between -10 and 10")
            )
            (print (series x n 0 2 0))
        )
        (print "X and N must be integers")
    )
)

(defun series (x n counter alternation total)
    (setq total
        (/ 
            (* (exponent -1 alternation 0) (exponent x counter 0))
            (factorial counter 1)
        )
    )
    
    (if (> n (+ 1 counter))
        (+ total (series x n (+ counter 2) (+ alternation 1) total))
        total
    )
)

(defun factorial (x counter)
    (if (> x counter)
        (* counter (factorial x (+ counter 1)))
        counter
    )
)

(defun exponent (x n counter)
    (if (= n 0)
        1
        (if (< (+ counter 1) n)
            (* x (exponent x n (+ counter 1)))
            x
        )
    )
)

(write "(sin-cos-comp 2 7):")
(sin-cos-comp 2 7)
(write-line "")
(print "(sin-cos-comp 2 6):")
(sin-cos-comp 2 6)
(write-line "")
(print "INVALID CASES:")
(sin-cos-comp 10 7)
(sin-cos-comp 1.5 7)
(sin-cos-comp 2 7.5)

Advertisements
Loading...

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