Addition Of Matrix In C

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

A matrix is a 2D array with elements in rows and columns. Matrices of the same dimensions (m rows and n columns) can be added;

The sum is a matrix of the same order, obtained by adding corresponding elements.

addition-of-two-matrix

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Program to Add Two Matrices

The following code can be used for matrix addition in C :

Output

The output of the matrix addition in the C code is as below.

Program Explanation

In the above program,

  • We have three matrices: ' mat1, mat2, and result`.
  • The matrix mat1 will store the first matrix, the matrix mat2 will store the second matrix, and the result matrix will store the sum of two matrices.
  • The user enters the order of matrices, i.e., the number of rows and the number of columns.
  • for loops are used to take the matrix elements.
  • Once the user enters both matrices, another for loop finds the sum of the two matrices.
  • The sum of two matrices is calculated by taking the sum of corresponding elements in both the matrix and stored in the matrix result.
  • Finally, the result matrix is printed.
  • In this way, we can perform matrix addition in c.

Conclusion

  • A matrix with the order mxn can be added with another matrix of the order mnm*n.
  • Adding the corresponding elements in the matrices will give the resultant element.
  • The resultant matrix will have the same order as that of the two matrices being added.
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more