-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab8P1.c
63 lines (58 loc) · 1.21 KB
/
lab8P1.c
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
#include <stdio.h>
#include <stdbool.h>
void ReadArray(FILE *inp, int x[][6]);
void ReadArray(FILE *inp, int x[][6])
{
int i, j, row = 0, col = 0, diag = 0;
bool magic = false;
for (i = 0; i < 6; i++)
{
for (j = 0; j < 6; j++)
{
fscanf(inp, "%d", &x[i][j]);
}
}
for (i = 0; i < 6; i++)
{
for (j = 0; j < 6; j++)
{
if (x[i][j] == x[j][i])
{
magic = true;
}
}
}
if (magic == true)
{
for (i = 0; i < 6; i++)
{
for (j = 0; j < 6; j++)
{
printf("%d\t", x[i][j]);
}
printf("\n");
}
for (i = 0; i < 6; i++)
{
col += x[i][0];
}
for (i = 0; i < 6; i++)
{
row += x[0][i];
}
j = 0;
for (i = 0; i < 6; i++)
{
diag += x[i][j++];
}
printf("Sum of numbers in a row: %d\nSum of numbers in a column: %d\nSum of numbers in a diagonal: %d\n", row, col, diag);
}
}
int main()
{
FILE *inp;
inp = fopen("array.txt", "r");
int x[6][6];
ReadArray(inp, x);
return 0;
}