fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define W 8
  4. #define H 6
  5. char map[H][W] = {
  6. {1, 1, 1, 1, 1, 1, 1, 1},
  7. {1, 0, 0, 0, 1, 0, 0, 1},
  8. {1, 1, 1, 0, 1, 0, 0, 1},
  9. {1, 0, 0, 0, 0, 0, 1, 1},
  10. {1, 0, 1, 1, 1, 0, 2, 1},
  11. {1, 1, 1, 1, 1, 1, 1, 1},
  12. };
  13. void maze1(int x, int y, int depth) {
  14. int i;
  15. for (i = 0; i < depth * 2; i++) {
  16. printf(" ");
  17. }
  18.  
  19. if (map[y][x] == 0) {
  20. printf("(%d,%d)\n", x, y);
  21. maze1(x + 1, y, depth + 1);
  22. maze1(x, y + 1, depth + 1);
  23. }
  24. else if (map[y][x] == 1) {
  25. printf("(%d,%d)X\n", x, y);
  26. }
  27. else if (map[y][x] == 2) {
  28. printf("(%d,%d) OK\n", x, y);
  29. exit(0);
  30. }
  31. }
  32. int main(void) {
  33. printf("\n");
  34. maze1(1, 1, 0);
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
(1,1)
  (2,1)
    (3,1)
      (4,1)X
      (3,2)
        (4,2)X
        (3,3)
          (4,3)
            (5,3)
              (6,3)X
              (5,4)
                (6,4) OK