fork download
  1. #include <stdio.h>
  2. main( ) {
  3. int field[4][4] = { {0,1,0,1}, {0,0,0,1}, {1,1,1,0}, {0,1,1,1} };
  4. int mines[4][4] = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} };
  5. int w = 4, h = 4;
  6. for (int y = 0; y < h; y++) {
  7. for (int x = 0; x < w; x++) {
  8. if (field[y][x] == 0) continue;
  9. for (int j = y - 1; j <= y + 1; j++) {
  10. for (int i = x - 1; i <= x + 1; i++) {
  11. if (chkover(w, h, j, i) == 1)
  12. mines[j][i] += 1;
  13. }
  14. }
  15. }
  16. }
  17. }
  18. int chkover(int w, int h, int j, int i) {
  19. if (i >= 0 && i < w && j >= 0 && j < h) return 1;
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty