Addition of Two Matrix in C Programming

A Matrix is Two dimensional array that have number of rows and columns. Addition of Two Matrix in C Programming is very easy.

To write program for adding two matrix is same as we perform matrix addition in mathematics.

To Add Two Numbers rows and columns of both matrix should be same.

Element of each row and column of matrix A will added with same row and column element in matrix B.

The sum of both matrix will produce same row and column matrix in resultant matrix.

Example: Write a program to add two matrix. Firstly, ask from user order of matrix( number of rows and column).

Then take the elements of matrix from user as a input and print the resultant matrix

For example,

if a user input order as 3,3, i.e., three rows and three columns and
First matrix                      
1             2             3
4             5             6
7             8             9

Second matrix:
9             8             7
6             5             4
3             2             1


then the output of the program (addition of two 3*3 matrix in c) is:

10           10           10
10           10           10
10           10           10

Steps for Addition of Two Matrix in C Programming

  1. Declare Three matrix f,s and sum.
  2. Take elements for matrix f and s.
  3. Add both matrix f and s and save to sum matrix.
  4. Print the sum matrix.

Matrix addition program in C

Number of rows and columns are controlled by variable m and n.

To avoid checking again row and column of both matrix it is accepted at only one place and used by both matrix.

Both Matrix elements are taken from user as per requirement user can also declare matrix elements in program.

OUTPUT

Hope you got how to add two matrix in C. Similar way you can also write program to multiply two matrix.