#### Aim:

Write a program to perform addition of two square matrices

#### Program:

row=int(input("Enter No of Rows for 1st Matrix:")) column=int(input("Enter No of column for 1nd Matrix:")) row1=int(input("Enter No of Rows for 2st Matrix:")) column1=int(input("Enter No of column for 2nd Matrix:")) X = [[int(input(("Enter value for X[",i,"][",j,"]:"))) for j in range(column)] for i in range(row)] Y = [[int(input(("Enter value for Y[",i,"][",j,"]:"))) for j in range(column1)] for i in range(row1)] print("1st Matrix X:",X) print("2st Matrix Y:",Y) if (row==row1 and column==column1): result = [[X[i][j] + Y[i][j] for j in range(len(X))] for i in range(len(X[0]))] print(result) else: print("Adition 2 Matrix not Possible")

#### Output:

Enter No of Rows for 1st Matrix: 2 Enter No of column for 1nd Matrix: 2 Enter No of Rows for 2st Matrix: 2 Enter No of column for 2nd Matrix: 2 ('Enter value for X[', 0, '][', 0, ']:')1 ('Enter value for X[', 0, '][', 1, ']:')2 ('Enter value for X[', 1, '][', 0, ']:')3 ('Enter value for X[', 1, '][', 1, ']:')4 ('Enter value for Y[', 0, '][', 0, ']:')5 ('Enter value for Y[', 0, '][', 1, ']:')6 ('Enter value for Y[', 1, '][', 0, ']:')7 ('Enter value for Y[', 1, '][', 1, ']:')8 1st Matrix X: [[1, 2], [3, 4]] 2st Matrix Y: [[5, 6], [7, 8]] [[6, 8], [10, 12]]