-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.cpp
89 lines (82 loc) · 1.65 KB
/
matrix.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
#include <iostream>
using namespace std;
#include <vector>
int diagonal(int arr[][3], int row, int col)
{
int sum = 0;
int sum1 = 0;
if (row % 2 == 0 && col % 2 == 0)
{
// even matrix
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
if (i == j)
{
sum = sum + arr[i][j];
}
if (i + j == row - 1)
{
sum1 = sum1 + arr[i][j];
}
}
}
}
else
{
// odd matrix
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
if (i == j)
{
sum = sum + arr[i][j];
}
if (i + j == row - 1 && i != j)
{
sum1 = sum1 + arr[i][j];
}
}
}
}
return sum1 + sum;
}
void rotate(int arr[][3], int n, int m, int ans[][3])
{
ans[n][m] = 0;
int k = 0;
int l = 0;
for (int j = 0; j < m; j++)
{
for (int row = n - 1; row >= 0; row--)
{
ans[k][l] = arr[row][j];
l++;
}
k++;
}
}
int main()
{
int arr[3][3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cin >> arr[i][j];
}
}
// cout << diagonal(arr, 3, 3) << endl;
int ans[3][3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout << ans[i][j] << " ";
}
cout << endl;
}
return 0;
}