-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
29 lines (27 loc) · 895 Bytes
/
common.h
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
/// this requires that GSIZE
#define GP( t, x ) int Grows, int Gcols, t x [Grows][Gcols]
void showGridZone(int topx, int topy, int w, int h, GP( int, grid ) ){
printf("\n");
printf("# Grid zone {topx,topy}={%d,%d}, {w,h}={%d,%d}\n", topx, topy, w, h);
printf("# --------------------------------------------------\n");
int v=0;
long ysums=0;
long yproducts=1;
long xs=0;
long xp=1;
for(int y=topy;y<h+topy;y++){
printf("# y: %5d | ", y);
xs=0; xp=1;
for(int x=topx;x<w+topx;x++){
v=grid[y][x];
xs+=v; xp*=v;
printf("%3d ", v);
}
printf(" | lsum: %8ld | lproduct: %8ld\n", xs, xp);
ysums+=xs; yproducts*=xp;
}
printf("# --------------------------------------------------\n");
printf("# Total sum: %8ld\n", ysums);
printf("# Total product: %10ld\n", yproducts);
printf("\n");
}