elibraryportal Logo

Addition Multiplication of Two Matrices in C

Example 1

Output

 First Matrix:
5 6 7
8 9 10
3 1 2
Second Matrix:
1 2 3
4 5 6
7 8 9

Choose the matrix operation,
----------------------
1. Addition
2. Subtraction
3. Multiplication
4. Transpose
5. Exit
----------------------
Enter your choice: 1
Sum of matrix:
6 8 10
12 14 16
10 9 11

Choose the matrix operation,
----------------------
1. Addition
2. Subtraction
3. Multiplication
4. Transpose
5. Exit
----------------------
Enter your choice: 2
Subtraction of matrix:
4 4 4
4 4 4
-4 -7 -7

Choose the matrix operation,
----------------------
1. Addition
2. Subtraction
3. Multiplication
4. Transpose
5. Exit
----------------------
Enter your choice: 3
Multiplication of matrix:
78 96 114
114 141 168
21 27 33

Choose the matrix operation,
----------------------
1. Addition
2. Subtraction
3. Multiplication
4. Transpose
5. Exit
----------------------
Enter your choice: 4
Transpose of the first matrix:
5 8 3
6 9 1
7 10 2
Transpose of the second matrix:
1 4 7
2 5 8
3 6 9

Choose the matrix operation,
----------------------
1. Addition
2. Subtraction
3. Multiplication
4. Transpose
5. Exit
----------------------
Enter your choice: 6
Invalid input.
Please enter the correct input.

Choose the matrix operation,
----------------------
1. Addition
2. Subtraction
3. Multiplication
4. Transpose
5. Exit
----------------------
Enter your choice: 5
Thank You.

Example 2

Output

 Enter no. of rows and columns in matrix A: 3 3
Enter no. of rows and columns in matrix B: 3 3
Enter elements of matrix A:
1 1 1
2 2 2
3 3 3
Enter elements of matrix B:
2 2 2
2 2 2
2 2 2

Result of Matirx Addition:
3 3 3
4 4 4
5 5 5

Result of Matirx Multiplication:
6 6 6
12 12 12
18 18 18
Next Topic