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 (fact digit)))
(setf n (floor n 10))
)
(if(= sum num) (print "Strong Number....")
(print "Not a Strong Number....")
)
t
)
(defun fact(n)
(if (= n 0) 1
(* n (fact(- n 1)))
)
)
Output:
Break 18 [19]> (load 'str1.lsp)
;; Loading file str1.lsp ...
;; Loaded file str1.lsp
T
Break 18 [19]> (str 145)
"Strong Number...."
T
Break 18 [19]>
2.To Generate
Program:
(defun str(nn)
(do((j 1 (+ j 1))) ((= j nn))
(setf n j)
(setf num n sum 1)
(loop for i from n above 0 do
(setf f1 (mod n 10))
(setf sum (+ sum (fact f1)))
(setf n (floor n 10))
(setf i n)
)
(if(= sum num) (print num))
)
t
)
(defun fact(n)
(if (= n 0) 1
(* n (fact(- n 1)))
)
)
Output:
Break 15 [16]> (load 'str.lsp)
;; Loading file str.lsp ...
;; Loaded file str.lsp
T
Break 15 [16]> (str 147)
145
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 (fact digit)))
(setf n (floor n 10))
)
(if(= sum num) (print "Strong Number....")
(print "Not a Strong Number....")
)
t
)
(defun fact(n)
(if (= n 0) 1
(* n (fact(- n 1)))
)
)
Output:
Break 18 [19]> (load 'str1.lsp)
;; Loading file str1.lsp ...
;; Loaded file str1.lsp
T
Break 18 [19]> (str 145)
"Strong Number...."
T
Break 18 [19]>
2.To Generate
Program:
(defun str(nn)
(do((j 1 (+ j 1))) ((= j nn))
(setf n j)
(setf num n sum 1)
(loop for i from n above 0 do
(setf f1 (mod n 10))
(setf sum (+ sum (fact f1)))
(setf n (floor n 10))
(setf i n)
)
(if(= sum num) (print num))
)
t
)
(defun fact(n)
(if (= n 0) 1
(* n (fact(- n 1)))
)
)
Output:
Break 15 [16]> (load 'str.lsp)
;; Loading file str.lsp ...
;; Loaded file str.lsp
T
Break 15 [16]> (str 147)
145
T
Break 15 [16]>
0 comments:
Post a Comment