-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaths_dm_code.cpp
More file actions
68 lines (67 loc) · 1.82 KB
/
maths_dm_code.cpp
File metadata and controls
68 lines (67 loc) · 1.82 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
#include<bits/stdc++.h>
using namespace std;
int main(){
int matrix[4][4];
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
cout << "Enter value for element at [" << i << "][" << j << "] = ";
cin >> matrix[i][j];
}
}
for(int z=0 ; z<4 ; z++){
for(int i=0 ; i<4 ; i++){
cout<<matrix[z][i]<<" ";
}
cout<<endl;
}
for(int z=0 ; z<4 ; z++){
vector<pair<int,int>> column(4);
vector<pair<int,int>> row(4);
for(int i=0 ; i<4 ; i++){
column[i].first=i;
column[i].second=matrix[i][z];
}
for(int i=0 ; i<4 ; i++){
row[i].first=i;
row[i].second=matrix[z][i];
}
int columnsum=0;
int rowsum=0;
for(int i=0 ; i<4 ; i++){
columnsum+=column[i].second;
rowsum+=row[i].second;
}
cout<<endl;
cout<<"columsum="<<columnsum<<"rowsum="<<rowsum<<endl;
vector<pair<int,int>>shortcolumn;
vector<pair<int,int>>shortrow;
for(int i=0 ; i<4 ; i++){
if(column[i].second){
shortcolumn.push_back(column[i]);
} else {
continue;
}
}
for(int i=0 ; i<4 ; i++){
if(row[i].second){
shortrow.push_back(row[i]);
} else {
continue;
}
}
if(columnsum&&rowsum){
for(int i=0 ; i<columnsum ; i++){
for(int j=0 ; j<rowsum ; j++){
matrix[shortcolumn[i].first][shortrow[j].first]=1;
}
}
}
}
cout<<"The matrix is : "<<endl;
for(int z=0 ; z<4 ; z++){
for(int i=0 ; i<4 ; i++){
cout<<matrix[z][i]<<" ";
}
cout<<endl;
}
}