0% found this document useful (0 votes)
27 views

STD Main M, N, C, D, First, Second, Sum: Using Namespace

This C++ program allows a user to input the dimensions and elements of two matrices, calculates the sum of the matrices by adding corresponding elements, and outputs the summed matrix. It prompts the user to enter the number of rows and columns for the matrices, then uses nested for loops to input the elements of each matrix and calculate the sum matrix by adding matching elements from the first and second matrices.

Uploaded by

abhi kr
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

STD Main M, N, C, D, First, Second, Sum: Using Namespace

This C++ program allows a user to input the dimensions and elements of two matrices, calculates the sum of the matrices by adding corresponding elements, and outputs the summed matrix. It prompts the user to enter the number of rows and columns for the matrices, then uses nested for loops to input the elements of each matrix and calculate the sum matrix by adding matching elements from the first and second matrices.

Uploaded by

abhi kr
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Matrix Addition

#include<iostream>
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 elements of first matrix\n";
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
cin >> first[c][d];
cout << "Enter the elements of second 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;

You might also like