C Exercises: Addition of two Matrices
19. Matrix Addition
Write a program in C for addition of two Matrices of same size.
The task is to write a C program that adds two square matrices of the same size. The program prompts the user to input the size of the matrices (less than 5), elements for each matrix, and then calculates the sum of the matrices. It displays the original matrices and their sum as output.
Visual Presentation:

Sample Solution:
C Code:
Sample Output:
Addition of two Matrices : ------------------------------ Input the size of the square matrix (less than 5): 2 Input elements in the first matrix : element - [0],[0] : 1 element - [0],[1] : 2 element - [1],[0] : 3 element - [1],[1] : 4 Input elements in the second matrix : element - [0],[0] : 5 element - [0],[1] : 6 element - [1],[0] : 7 element - [1],[1] : 8 The First matrix is : 1 2 3 4 The Second matrix is : 5 6 7 8 The Addition of two matrix is : 6 8 10 12
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to add two matrices and then subtract the second matrix from the first.
- Write a C program to add two matrices and compute the sum of all elements of the resulting matrix.
- Write a C program to add two matrices using pointer arithmetic.
- Write a C program to add two matrices and then multiply the resulting matrix by a scalar value.
C Programming Code Editor:
Previous: Write a program in C for a 2D array of size 3x3 and print the matrix.
Next: Write a program in C for subtraction of two Matrices.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.