Thought Sharing

Monday, April 2, 2012

Program for Addition of 2 Matrices in C++

#include
#include

Void main()
{
int m, n, i, j, A[10][10], B[10][10], C[10][10];

cout << "Enter the number of rows and columns of matrix ";
cin >> m >> n;

cout << "Enter the elements of first matrix\n";
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
cin >> A[i][j];

cout << "Enter the elements of second matrix\n";
for ( i = 0 ; i < m ;i++ )
for ( j = 0 ; j < n ; j++ )
cin >> B[i][j];

for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
sum[i][j] = A[i][j] + B[i][j];

cout << "Sum of entered matrices:-\n";
for ( i = 0 ; i < m ; i++ )
{
for ( j = 0 ; j < n ; j++ )
cout << C[i][j] << "\t";
cout << endl;
}

getch();
}