C Program to Add Two Matrices Using Multi-dimensional Arrays
Code Explanation :
In this example you'll learn to use two-dimensional arrays to add two matrices during C programming.
The user is asked to enter in this program for the number of rows
r and the columns
c. The user is then asked to enter the elements of the two matrices (order
We then inserted the corresponding two-matrix elements and stored them in another matrix (two-dimensional array). The result is eventually written onto the board.
We are going to represent this code into algorithm and flowchart.
STEP 1 : Start
STEP 2 : Declare array a, b, sum with r, c,
i, j and k
STEP 3 : Read r and c
STEP 4 : Repeat this step until i < r
STEP 4.1 : Repeat this step until j < c
STEP 4.1.1 : Read for a[i][j]
STEP 4.1.2 : j++
STEP 4.2 : i++
STEP 5 : Repeat this step until i < r
STEP 5.1 : Repeat this step until j < c
STEP 5.1.1 : Read for b[i][j]
STEP 5.1.2 : j++
STEP 5.2 : i++
STEP 6 : Repeat this step until i < r
STEP 6.1 : Repeat this step until j < c
STEP 6.1.1 : sum[i][j] = a[i][k] + b[k][j]
STEP 6.1.2 : j++
STEP 6.2 : i++
STEP 7 : Repeat this step until i < r
STEP 7.1 : Repeat this step until j < c
STEP 7.1.1 : Print sum[i][j] with tab
STEP 7.1.2 : j++
STEP 7.2 : Print "n" for line break
STEP 7.3 : i++
STEP 8 : End
If you got any difficulty on understanding this example, leave comment. we will explain you with more explanation.
Our example mainly covers following topics in any programing
- Basic Programs
- Number Programs
- Array Programs
- Matrix Programs
- Pattern Programs
- String Programs
- Tree Programs
- Singly Linked List Programs
- Circular Linked List Programs
- Doubly Linked List Programs
Here we share programs on various topics such as array strings, series area & volume of geometric figures, mathematical calculation algorithms for sorting & searching and much more.Our goal is to provide you with the perfect solution to all the programming problems you may have encountered either during interviews or in class assignments. If you don’t find what you are looking for then please drop a line in the comment section of example page or you can request from account page so that we can get it added to the below collection of programs. Happy Learning!!
If you are confident with the above programs and are able to successfully understand and run them without any problems then it is time for you to take a step further and learn comprehensive programming principles using examples and flow diagrams. Here is the link: Programming tutorial lists .
If you find this example helpful, don't forget to share it with your friends. And stay updated with us by subscribing adzetech.
If you find any code error or grammetical error then you can suggest for example improvement on clicking below button.