-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAss1.cpp
More file actions
249 lines (180 loc) · 4.82 KB
/
Ass1.cpp
File metadata and controls
249 lines (180 loc) · 4.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//Reverse an array
/*
#include<iostream>
using namespace std;
void Reverse(int arr[],int start,int end){
while(start<=end){
int temp=arr[start];
arr[start]=arr[end];
arr[end]=temp;
start++;
end--;
}
}
int main(){
int arr[]={1,2,3,4};
int n=sizeof(arr)/sizeof(arr[0]);
Reverse(arr,0,n-1);
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
return 0;
}*/
//Multiplication of matrix
// #include<iostream>
// using namespace std;
// int main(){
// int A[100][100];
// int B[100][100];
// int product[100][100];
// int sum=0;
// int Arows,Acolumns;
// int Brows,Bcolumns;
// cout<<"Enter the rows matrix A:";
// cin>>Arows;
// cout<<"Enter the colums of matrix A:";
// cin>>Acolumns;
// cout<<"Enter the rows of matrix B:";
// cin>>Brows;
// cout<<"Enter the columns of matrix B:";
// cin>>Bcolumns;
// cout<<"Enter the elements of matrix A:\n";
// for(int i=0;i<Arows;i++){
// for(int j=0;j<Acolumns;j++){
// cin>>A[i][j];
// cout<<" ";
// }
// cout<<"\n";
// }
// cout<<"Enter the elements of matrix B:\n";
// for(int i=0;i<Brows;i++){
// for(int j=0;j<Bcolumns;j++){
// cin>>B[i][j];
// cout<<" ";
// }
// cout<<"\n";
// }
// for(int i=0;i<Arows;i++){
// for(int j=0;j<Bcolumns;j++){
// for(int k=0;k<Brows/*Acolums*/;k++){//you can also take acolumns
// sum +=A[i][k]*B[k][j];
// }
// product[i][j]=sum;
// sum=0;
// }
// }
// cout<<"Resultant matrix";
// for(int i=0;i<Arows;i++){
// for(int j=0;j<Bcolumns;j++){
// cout<<product[i][j];
// cout<<" ";
// }
// cout<<"\n";
// }
// return 0;
// }
//Transpose of matrix
// #include<bits/stdc++.h>
// using namespace std;
// int main(){
// int rows,cols;
// cout<<"Enter the number of rows :";
// cin>>rows;
// cout<<"Enter the number of columns :";
// cin>>cols;
// int matrix[100][100];
// int transpose[100][100];
// cout<<"Enter the elements of the matrix "<<endl;
// for(int i=0;i<rows;i++){
// for(int j=0;j<cols;j++){
// cout<<"Enter the ["<<i<<","<<j<<"]";
// cin>>matrix[i][j];
// }
// }
// //computing the transpose
// for(int i=0;i<rows;i++){
// for(int j=0;j<cols;j++){
// transpose[j][i]=matrix[i][j];
// }
// }
// for(int i=0;i<cols;i++){
// for(int j=0;j<rows;j++){
// cout<<transpose[i][j];
// }
// cout<<endl;
// }
// return 0;
// }
//To find sum odf every row and colum
// #include<bits/stdc++.h>
// using namespace std;
// int main(){
// int rows,cols;
// int matrix[100][100];
// cout<<"Enter the number of rows :";
// cin>>rows;
// cout<<"Enter the number of columns :";
// cin>>cols;
// for(int i=0;i<rows;i++){
// for(int j=0;j<cols;j++){
// cout<<"Enter the element with ["<<i<<","<<j<<"]";
// cin>>matrix[i][j];
// cout<<" ";
// }
// cout<<endl;
// }
// //To find rowSum --->traverse the matrix using rows
// for(int i=0;i<rows;i++){
// int rowSum=0;
// for(int j=0;j<cols;j++){
// rowSum+=matrix[i][j];
// }
// cout<<"The sum of row "<<i<<" ="<<rowSum<<endl;
// }
// //To find colSum --->traverse the matrix using the column
// for(int j=0;j<cols;j++){
// int colSum=0;
// for(int i=0;i<rows;i++){
// colSum+=matrix[i][j];
// }
// cout<<"Sum of column "<<j<<"="<<colSum<<endl;
// }
// return 0;
// }
/*2) Design the logic to remove the duplicate elements from an Array and after the
deletion the array should contain the unique elements*/
// #include<bits/stdc++.h>
// using namespace std;
// int main(){
// set<int> st;
// int arr[]={1,2,2,3,4,5,7,112,110,123,14,9,0,4};
// int n=sizeof(arr)/sizeof(arr[0]);
// for(int i=0;i<n;i++){
// st.insert(arr[i]);
// }
// int index=0;
// for(auto it:st){
// arr[index]=it;
// index++;
// }
// cout<<"Array after removing duplicates (sorted) :";
// for(int i=0;i<index;i++){
// cout<<arr[i]<<" ";
// }
// cout<<"\n";
// return 0;
// }
//Predict the output
// #include<bits/stdc++.h>
// using namespace std;
// int main(){
// int j;
// int arr[5]={1};
// for(int i=0;i<5;i++){
// cout<<arr[i]<<" ";
// }
// return 0;
// }
/*In C++, when you initialize an array like int arr[5] = {val};,
only the first element is explicitly initialized, and the remaining elements are zero-initialized automatically if the array is defined with this brace-enclosed initializer.*/