HomeC++

C++ Program to Add Two Matrices

C++ Program to Add Two Matrices
Like Tweet Pin it Share Share Email

Today we make a simple C++ Program To add two matrices in C++ Programming, you have to ask to the user to enter the elements of both the matrix, now start adding the two matrix to form a new matrix. 

C++ Program to Add Two Matrices

#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int m, n, c, d, first[10][10], second[10][10], sum[10][10];

cout << "Enter the Number of Rows and Columns of Matrix:";
cin >> m >> n;
cout << "Enter the First Elements of Matrix:\n";

for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
cin >> first[c][d];

cout << "Enter the Second elements of matrix:\n";

for ( c = 0 ; c < m ;c++ )
for ( d = 0 ; d < n ; d++ )
cin >> second[c][d];

for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
sum[c][d] = first[c][d] + second[c][d];

cout << "Sum of Entered matrices:-\n";

for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
cout << sum[c][d] << "\t";

cout << endl;
}

return 0;
}

Output of ProgramC++ Program to Add Two Matrices

Comments (0)

Leave a Reply

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