1.To Check
Program
(defun str(n)
(setf num n sum 0)
(loop while (/= n 0) do
(setf digit (mod n 10))
(setf sum (+ sum (* (* digit digit) digit)))
(setf n (floor n 10))
)
(if(= sum num) (print "Armstrong Number....")
(print "Not a Armstrong Number....")
)
t)
Output:
Break 20 [21]> (load 'arstr.lsp)
;; Loading file arstr.lsp ...
;; Loaded file arstr.lsp
T
Break 20 [21]> (str 153)
"Armstrong Number...."
T
Break 20 [21]>
2.To Generate
Program:
(defun arm(rang)
(do((j 1 (+ j 1))) ((= j rang))
(setf n j)
(setf num n sum 1)
(loop for i from n above 0 do
(setf f1 (mod n 10))
(setf sum (+ sum (* (* f1 f1) f1)))
(setf n (floor n 10))
(setf i n)
)
(if(= sum num) (print num))
)
t
)
Output:
Break 15 [16]> (load 'arm.lsp)
;; Loading file arm.lsp ...
;; Loaded file arm.lsp
T
Break 15 [16]> (str 157)
153
T
Break 15 [16]>
Program
(defun str(n)
(setf num n sum 0)
(loop while (/= n 0) do
(setf digit (mod n 10))
(setf sum (+ sum (* (* digit digit) digit)))
(setf n (floor n 10))
)
(if(= sum num) (print "Armstrong Number....")
(print "Not a Armstrong Number....")
)
t)
Output:
Break 20 [21]> (load 'arstr.lsp)
;; Loading file arstr.lsp ...
;; Loaded file arstr.lsp
T
Break 20 [21]> (str 153)
"Armstrong Number...."
T
Break 20 [21]>
2.To Generate
Program:
(defun arm(rang)
(do((j 1 (+ j 1))) ((= j rang))
(setf n j)
(setf num n sum 1)
(loop for i from n above 0 do
(setf f1 (mod n 10))
(setf sum (+ sum (* (* f1 f1) f1)))
(setf n (floor n 10))
(setf i n)
)
(if(= sum num) (print num))
)
t
)
Output:
Break 15 [16]> (load 'arm.lsp)
;; Loading file arm.lsp ...
;; Loaded file arm.lsp
T
Break 15 [16]> (str 157)
153
T
Break 15 [16]>
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic.
ReplyDeleteSelenium Training in Electronic City