-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_add.lisp
56 lines (53 loc) · 1.29 KB
/
matrix_add.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(defun addNxN (A B)
(if
(mismatch (array-dimensions A)(array-dimensions B))
(progn
(format t "Matrix Non Compatible")
(return-from addNxN 0)
)
)
(setq C (make-array (array-dimensions A)))
(loop for i from 0 to (- (car (array-dimensions A)) 1)
do(
loop for j from 0 to (- (car (reverse(array-dimensions A))) 1 )
do
(setf (aref C i j) (+ (aref A i j) (aref B i j)))
)
)
(return-from addNxN C)
)
(defun printmatrix (A)
(format t "The Resultant Matrix is ")
(terpri)
(loop for i from 0 to (- (car (array-dimensions A)) 1)
do(
loop for j from 0 to (- (car (reverse(array-dimensions A))) 1 )
do
(format t "~D " (aref A i j))
)
(terpri)
)
)
(format t "Enter N for First Matrix")
(setf n1 (read))
(format t "Enter N for Second Matrix")
(setf n2 (read))
(setf A (make-array (list n1 n1)))
(dotimes (i n1)
(
dotimes (j n1)
(format t "Enter ~D ~D th Element of First Matrix" i j)
(terpri)
(setf (aref A i j) (read))
)
)
(setf B (make-array (list n2 n2)))
(dotimes (i n2)
(
dotimes (j n2)
(format t "Enter ~D ~D th Element of Second Matrix" i j)
(terpri)
(setf (aref B i j) (read))
)
)
(printmatrix (addNxN A B))