-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubtract_matrix.cpp
More file actions
147 lines (128 loc) · 3.61 KB
/
subtract_matrix.cpp
File metadata and controls
147 lines (128 loc) · 3.61 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include<iostream>
using namespace std;
int main()
{
int mat1[3][3], mat2[3][3], mat3[3][3];
/* Initializing Mat1 and Mat2 */
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
mat1[i][j] = i + 1;
mat2[i][j] = j + 1;
}
}
/* Adding matrices Mat1 and Mat2 */
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
mat3[i][j] = mat2[i][j] - mat1[i][j];
}
}
cout << "First Matrix : " << endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout << mat1[i][j] << "\t";
}
cout << endl;
}
cout << "Second Matrix : " << endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout << mat2[i][j] << "\t";
}
cout << endl;
}
cout << "Third Matrix = Second Matrix - First Matrix : " << endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout << mat3[i][j] << "\t";
}
cout << endl;
}
}
ADVERTISEMENT
$ g++ main.cpp
$ ./a.out
First Matrix :
1 1 1
2 2 2
3 3 3
Second Matrix :
1 2 3
1 2 3
1 2 3
Third Matrix = Second Matrix - First Matrix :
0 1 2
-1 0 1
-2 -1 0
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
If you find any mistake above, kindly email to enquiry@sanfoundry.com
« Prev - C++ Program to Add Two Matrices» Next - C++ Program to Check if a Matrix is Diagonal Matrix
Related Posts:
Practice Computer Science MCQs
Apply for C++ Internship
Apply for Computer Science Internship
Check C++ Books
Practice Programming MCQs
advertisement
ADVERTISEMENT
Recommended Articles:
C# Program to Subtract Two Matrices
C Program to Subtract Two Matrices
C++ Program to Find Transpose of a 3 x 3 Matrix
C++ Program to Add Two Matrices
C++ Program to Check Multiplicability of Two Matrices
C++ Program to Find Dot Product of Two Matrices
C Program to Perform Addition, Subtraction and Trace of 2 Matrices
C Program to Find Sum and Difference of Two Matrices
C Program to Check if Two Matrices are Equal
C Program to Check Multiplicability of Two Matrices
advertisement
ADVERTISEMENT
Additional Resources:
C++ Matrix Programs
C Programs on Matrix
Java Matrix Programs
C# Programs on Events
C# Programs
Popular Pages:
C++ Programs
C++ Algorithm Library
C# Programs on Functions
C# Interface Examples
C# Programs on Threads
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!
Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at SanfoundryManish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.
Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.
.
About | Certifications | Internships | Jobs | Privacy Policy | Terms | Copyright | Contact
© 2011-2024 Sanfoundry. All Rights Reserved.
Scroll back to top
Branchwise MCQs
School MCQs
DSA
Test
Job
Internship
Training
Videos
Books
Contact
C++ Programming
C++ Programs
C++ Programs - Array
C++ Programs - Matrix
C++ Programs - Matrix Types
C++ Programs - File Handling
C++ Resources