Program:
(defun linsearch(n)
(format t "~&<<LINEARSEARCH >>")
(readn n)
(format t "~&Enter the number to be searched:")
(setf num (read))
(setf flag 1)
(do ((x 0 (+ x 1))) ((= x n))
(if(= num (aref arr x))
(setf flag 2)
)
)
(if (= flag 2)
(format t "Number present...")
(format t "Number not present...")
)
)
(defun readn(n)
(setf arr (make-array n))
(format t "~&Enter the ~d numbers:" n )
(dotimes (x n t)
(setf (aref arr x) (read))
)
)
Output:
Break 4 [5]> (load 'ls.lsp)
;; Loading file ls.lsp ...
;; Loaded file ls.lsp
T
Break 4 [5]> (linsearch 5)
<<LINEARSEARCH >>
Enter the 5 numbers:1
2
3
4
5
Enter the number to be searched:4
Number present...
NIL
Break 4 [5]>
(defun linsearch(n)
(format t "~&<<LINEARSEARCH >>")
(readn n)
(format t "~&Enter the number to be searched:")
(setf num (read))
(setf flag 1)
(do ((x 0 (+ x 1))) ((= x n))
(if(= num (aref arr x))
(setf flag 2)
)
)
(if (= flag 2)
(format t "Number present...")
(format t "Number not present...")
)
)
(defun readn(n)
(setf arr (make-array n))
(format t "~&Enter the ~d numbers:" n )
(dotimes (x n t)
(setf (aref arr x) (read))
)
)
Output:
Break 4 [5]> (load 'ls.lsp)
;; Loading file ls.lsp ...
;; Loaded file ls.lsp
T
Break 4 [5]> (linsearch 5)
<<LINEARSEARCH >>
Enter the 5 numbers:1
2
3
4
5
Enter the number to be searched:4
Number present...
NIL
Break 4 [5]>
0 comments:
Post a Comment