____________________________________________
(defun ncifra (n)
(setq suma 0)
(while (> n 0)
(setq r( mod n 10))
(setq n( / n 10 ))
(setq suma( + suma r))
)
)
(ncifra 45)
____________________________________________
(defun par(a)
(setq r (mod a 2))
(if (= r 0) 'es_par 'es_impar)
)
(par 6)
____________________________________________
(defun discri(a b c)
(setq d (-(* b b) (* 4 a c)))
(if (< d 0) 'no-tiene-solucion-real (/(- (sqrt d) b) (* 2 a)))
)
(discri 2 8 1)
____________________________________________
(defun suma (n)
(setq suma 0)
(setq i 0)
(while (< i n )
(setq i (+ i 1))
(setq m (* i 5))
(setq suma (+ suma n))
)
)
(suma 5)
____________________________________________
(defun primo(n)
(setq i 2)
(while (< i n )
(setq r (mod n i))
( if (= r 0)
(setq i( + n 1))
(setq i( + i 1))
)
)
(if (> i n) 'no_es_primo 'es_primo)
)
(primo 8)
____________________________________________
No hay comentarios:
Publicar un comentario