forked from zzy590/basicLibPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHalf_diagonal_matrix.cpp
More file actions
101 lines (63 loc) · 1.09 KB
/
Half_diagonal_matrix.cpp
File metadata and controls
101 lines (63 loc) · 1.09 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
#include<iostream>
using namespace std;
int main()
{
int a[50][50], n, i, sum[4]={0,0,0,0}, b=1, j;
cout<<"Checking whether center element of matrix equals sum of half diagonals"<<endl<<endl;
cout<<"Enter value of order of matrix is an odd ordered matrix : ";
cin>>n;
for(i=0; i<n; i++)
{
for(int j=0; j<n; j++)
cin>>a[i][j];
}
cout<<endl<<endl;
for(i=0; i<n; i++)
{
for(int j=0; j<n; j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
for(i=0; i<n/2; i++)
{
sum[0]+=a[i][i];
}
cout<<endl<<"Sum of half diagonal 1 : "<<sum[0]<<endl;
i=n;
j=-1;
do
{
i--;
j++;
sum[1]+=a[i][j];
b++;
}while(b<=n/2);
cout<<endl<<"Sum of half diagonal 2 : "<<sum[1]<<endl;
i=-1;
j=n;
b=1;
do
{
i++;
j--;
sum[2]+=a[i][j];
b++;
}while(b<=n/2);
cout<<endl<<"Sum of half diagonal 3 : "<<sum[2]<<endl;
i=n;
j=n;
b=1;
do
{
i--;
j--;
sum[3]+=a[i][j];
b++;
}while(b<=n/2);
cout<<endl<<"Sum of half diagonal 4 : "<<sum[3]<<endl<<endl;
if(sum[0]==sum[1] && sum[1]==sum[2] && sum[2]==sum[3])
cout<<"Yes";
else
cout<<"No";
return 0;
}