Dr. A.P.J. Abdul Kalam Technical University (AKTU), Lucknow

Lab Exercise

26. Write a program to add and multiply two matrices.

Sample Input and Output

Stdin Inputs:

3 3 5 9 7 4 8 6 3 1 2 3 3 4 7 9 8 3 6 5 2 1

Sample Result:

***Input first matrix***
Input number of rows: 3
Input number of columns: 3
Input element 1 1: 5
Input element 1 2: 9
Input element 1 3: 7
Input element 2 1: 4
Input element 2 2: 8
Input element 2 3: 6
Input element 3 1: 3
Input element 3 2: 1
Input element 3 3: 2

***Input second matrix***

Input number of rows: 3
Input number of columns: 3
Input element 1 1: 4
Input element 1 2: 7
Input element 1 3: 9
Input element 2 1: 8
Input element 2 2: 3
Input element 2 3: 6
Input element 3 1: 5
Input element 3 2: 2
Input element 3 3: 1

***First Matrix***
5     9     7
4     8     6
3     1     2

***Second Matrix***
4     7     9
8     3     6
5     2     1

***Sum of Matrices***
9     16     16
12     11     12
8     3     3

***Multiplication of Matrices***
127     76     106
110     64     90
30     28     35

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top