-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays_10.cpp
64 lines (52 loc) · 1.92 KB
/
arrays_10.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
55
56
57
58
59
60
61
62
63
64
// Subtraction of two 1D Matrices
#include <iostream>
using namespace std;
int main()
{
cout<<"Rule: rows and columns must be equal to perform addition of two matrices. " << endl;
cout<<"Hence Size of Two Matrices Must Be Same. Being either rows or columns = 1" << endl;
cout <<"That is (m x 1) +( m x 1) format or (1 x n) + (1 x n) format " <<"\n";
cout <<"(m x 1) format = Column Matrix/ Column Vector " <<"\n";
cout <<"(1 x n) format = Row Matrix/ Row Vector " <<"\n";
cout <<"*********************************************************"<< endl;
int size;
cout << "Enter size of the 1st and 2nd array: " << endl;
cin >> size;
int mat1[size];
int mat2[size];
int resMat[size];
cout << "Enter elements in the 1st Matrix: " << endl;
for (int i = 0; i < size; i++)
{
cout << "Enter " <<i <<" th elements of mat1[" << i << "]: ";
cin >> mat1[i];
}
cout << "\n";
cout << "Enter elements in the 2nd Matrix: " << endl;
for (int i = 0; i < size; i++)
{
cout << "Enter " <<i <<" th elements of mat2[" << i << "]: ";
cin >> mat2[i];
}
cout << "\n";
for (int i = 0; i < size; i++)
{
resMat[i] = mat1[i] - mat2[i];
}
cout << "Representation of Addition of Matrix if it is :(m x 1) Column Matrix" << endl;
for (int i = 0; i < size; i++)
{
cout<< "|";
cout << resMat[i] ;
cout<< "|";
cout << "\n";
}
cout << "Representation of Addition of Matrix if it is :(1 x n) Row Matrix" << endl;
cout<<"[";
for (int i = 0; i < size; i++)
{
cout << resMat[i] << " " ;
}
cout<<"]";
return 0;
}