-
Notifications
You must be signed in to change notification settings - Fork 0
/
matsub.cpp
executable file
·104 lines (87 loc) · 1.62 KB
/
matsub.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
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
#include<iostream>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iomanip>
using namespace std;
class sub
{
public:
int a[100][100];
int b[100][100];
int sum[100][100];
int r,c;
void input(void);
void submat(void);
void disp(void);
};
void sub::input()
{
cout<<"Enter the rows and columns \n";
cin>>r>>c;
cout<<"Enter elements for 1st matrix\n";
for(int i=0;i<r;i++)
for (int j = 0; j < c; ++j)
{
cin>>a[i][j];
}
cout<<"Enter elements for 2nd matrix\n";
for(int i=0;i<r;i++)
for (int j = 0; j < c; ++j)
{
cin>>b[i][j];
}
}
void sub::submat()
{
for(int i=0;i<r;i++)
for (int j = 0; j < c; ++j)
{
sum[i][j]=a[i][j]-b[i][j];
}
}
void sub::disp()
{
cout<<"\n\n\n";
for(int i=0;i<40;i++)
cout<<"-";
cout<<endl;
cout<<"The two matrices are:\n";
cout<<"Matrix A:";
for(int i=0;i<15;i++)
cout<<" ";
cout<<"Matrix B:"<<endl;
for(int i=0;i<r;i++)
{ for (int j = 0; j < c; ++j)
{
cout<<a[i][j]<<" ";
}
for(int i=0;i<21;i++)
cout<<" ";
for (int j = 0; j < c; ++j)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
cout<<"\n\nSubtraction is:\n";
for(int i=0;i<40;i++)
cout<<"-";
cout<<endl;
for(int i=0;i<r;i++)
{
for (int j = 0; j < c; ++j)
{
cout<<sum[i][j]<<" ";
}
cout<<endl;
}
}
int main()
{
sub ob;
ob.input();
ob.submat();
ob.disp();
}