Skip to content

Commit c7ebb53

Browse files
authored
Create Day11-2D_arrays.c
1 parent 610c68e commit c7ebb53

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Sample Input
3+
4+
1 1 1 0 0 0
5+
0 1 0 0 0 0
6+
1 1 1 0 0 0
7+
0 0 2 4 4 0
8+
0 0 0 2 0 0
9+
0 0 1 2 4 0
10+
Sample Output
11+
12+
19
13+
14+
Input Format
15+
16+
There are 6 lines of input, where each line contains 6 space-separated integers that describe the 2D Array A.
17+
18+
Output Format
19+
20+
Print the maximum hourglass sum in A. */
21+
22+
#include <assert.h>
23+
#include <limits.h>
24+
#include <math.h>
25+
#include <stdbool.h>
26+
#include <stddef.h>
27+
#include <stdint.h>
28+
#include <stdio.h>
29+
#include <stdlib.h>
30+
#include <string.h>
31+
32+
int main() {
33+
int N = 6;
34+
int arr[N][N];
35+
36+
for(int arr1 = 0; arr1 < N; arr1++) {
37+
for(int arr2 = 0; arr2 < N; arr2++) {
38+
scanf("%d",&arr[arr1][arr2]);
39+
}
40+
}
41+
42+
int max = -500;
43+
int curr = 0;
44+
for(int arr1 = 0; arr1 < N - 2; arr1++) {
45+
for(int arr2= 0; arr2 < N - 2; arr2++) {
46+
int a = arr[arr1][arr2];
47+
int b = arr[arr1][arr2 + 1];
48+
int c = arr[arr1][arr2 + 2];
49+
int d = arr[arr1 + 1][arr2 + 1];
50+
int e = arr[arr1 + 2][arr2];
51+
int f = arr[arr1 + 2][arr2 + 1];
52+
int g = arr[arr1+ 2][arr2 + 2];
53+
54+
curr = a + b + c + d + e + f + g;
55+
if(curr > max) {
56+
max = curr;
57+
}
58+
}
59+
}
60+
61+
printf("%d", max);
62+
63+
return 0;
64+
}

0 commit comments

Comments
 (0)