Programming Examples

Write a program to perform the addition of two square matrices.


Write a program to perform the addition of two square matrices.

Solution

import numpy as np

# Initialize two square matrices
A = np.array([[1, 2, 3],
              [4, 5, 6],
              [7, 8, 9]])

B = np.array([[9, 8, 7],
              [6, 5, 4],
              [3, 2, 1]])

# Add the matrices
C = A + B

# Display the matrices
print("First Matrix:")
print(A)

print("\nSecond Matrix:")
print(B)

print("\nSum of the Matrices:")
print(C)
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad