-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp11.c
63 lines (54 loc) · 1.18 KB
/
p11.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 <math.h>
int main()
{
int array[400];
int i = 0;
int j;
int input;
printf ("Input number\n");
while (i < 400) {
scanf("%d", &input);
array[i] = input;
++i;
}
int matrix[20][20];
for (i = 0; i < 400; ++i) {
matrix[i/20][i % 20] = array[i];
}
long int maxproduct = 0;
long int product;
for (i = 0; i <= 16; ++i) {
for (j = 0; j <= 16; ++j) {
product = matrix[i][j] * matrix[i+1][j+1] * matrix[i+2][j+2] * matrix[i+3][j+3];
if (product > maxproduct) {
maxproduct = product;
}
}
}
for (i = 3; i < 20; ++i) {
for (j = 0; j <= 16; ++j) {
product = matrix[i][j] * matrix[i-1][j+1] * matrix[i-2][j+2] * matrix[i-3][j+3];
if (product > maxproduct) {
maxproduct = product;
}
}
}
for (i = 0; i < 20; ++i) {
for (j = 0; j <= 16; ++j) {
product = matrix[i][j] * matrix[i][j+1] * matrix[i][j+2] * matrix[i][j+3];
if (product > maxproduct) {
maxproduct = product;
}
}
}
for (i = 0; i <= 16; ++i) {
for (j = 0; j < 20; ++j) {
product = matrix[i][j] * matrix[i+1][j] * matrix[i+2][j] * matrix[i+3][j];
if (product > maxproduct) {
maxproduct = product;
}
}
}
printf("%lu\n", maxproduct);
}