-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2d Arrays
85 lines (73 loc) · 2.46 KB
/
2d Arrays
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
//wap to multiplication of two matrix
#include<bits/stdc++.h>
using namespace std;
int main(){
int arr1[2][3] = {{2,3,4},{9,6,1}}; // you can take input from user as well
int arr2[2][3] = {{1,4,3},{2,3,5}};
int result[2][3];
for(int i = 0 ; i < 2 ; i++){ // 2 -> row
for(int j = 0 ; j < 3 ; j++){ // 3 -> col
for(int k = 0 ; k < 2 ; k++){ //
result[i][j] = arr1[i][j] * arr2[i][j];
}
}
}
for(int i = 0 ; i < 2 ; i++){ // 2 -> row
for(int j = 0 ; j < 3 ; j++){ // 3 -> col
cout << result[i][j] << " ";
}
cout << endl;
}
return 0;
}
===================================================================================================================================================================================================================
//wap to find the transpose of a matrix
#include<bits/stdc++.h>
using namespace std;
int main(){
int arr1[2][3] = {{2,3,4},{9,6,1}}; // you can take input from user as well
int arr2[3][2];
for(int i = 0 ; i < 2 ; i++){ // 2 -> row
for(int j = 0 ; j < 3 ; j++){ // 3 -> col
arr2[j][i] = arr1[i][j];
}
}
// col -> row , row -> col
for(int i = 0 ; i < 3 ; i++){ // 2 -> row
for(int j = 0 ; j < 2 ; j++){ // 3 -> col
cout << arr2[i][j] << " ";
}
cout << endl;
}
return 0;
}
==============================================================================================================================================================
//wap to find the sum of right digonal of a matrix
#include<bits/stdc++.h>
using namespace std;
int main(){
int arr[3][3] = {{2,3,5},{8,7,6},{2,3,6}};
int sum = 0;
for(int i = 0 ; i < 3 ; i++){
for(int j = i ; j < 3 ; j++){
sum = sum + arr[i][j];
}
}
cout << " sum of right diogonal element: "<< sum ;
return 0;
}
================================================================================================================================================================
//wap to find the sum of left digonal of a matrix
#include<bits/stdc++.h>
using namespace std;
int main(){
int arr[3][3] = {{2,3,5},{8,7,6},{2,3,6}};
int sum = 0;
for(int i = 0 ; i < 3 ; i++){
for(int j = 0 ; j < i ; j++){
sum = sum + arr[i][j];
}
}
cout << " sum of left diogonal element: "<< sum ;
return 0;
}