-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddTwoMatrix-181.cpp
54 lines (47 loc) · 1.4 KB
/
addTwoMatrix-181.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Task-> Add two Matrix using loop.
1.Start.
2.Take input of Row's && Columns..
3.Take input of elements of matrix using Loop.
4.Add two Matrices && keep in result..
5.Show the result.
6.Stop.
*/
#include <iostream>
using namespace std;
int inputRows,inputColumns,i,j;
int firstMatrix[10][10],secondMatrix[10][10],result[10][10];
int matrixAdd()
{
cout << "Enter theno. of rows && Columns:" << endl;
cin >> inputRows >> inputColumns;
cout <<"Enter the elements of first Matrix : "<< endl;
for(i=0; i<inputRows; i++) {
for(j=0; j<inputColumns; j++) {
cin >> firstMatrix[i][j];
}
}
cout << "Enter the second Matrix :" << endl;
for(i=0; i<inputRows; i++) {
for(j=0; j<inputColumns; j++) {
cin >> secondMatrix[i][j];
}
}
//Addition part of Matrix...
for(i=0; i<inputRows; i++) {
for(j=0; j<inputColumns; j++) {
result[i][j]=firstMatrix[i][j]+secondMatrix[i][j];
}
}
//printing result
cout << "Sum of entered Matrices: "<< endl;
for(i=0; i<inputRows; i++) {
for(j=0; j<inputColumns; j++) {
cout <<"\t "<<result[i][j]<<"\n";
}
}
}
int main()
{
matrixAdd();
}