Advertisement
tdulik

Sachovnice

Aug 27th, 2020 (edited)
1,272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #define VEL 50
  4. void tiskniDalsiPoziceKone(int x, int y, bool navstiveno[VEL][VEL]) {
  5.     if (x >= 0 && y >= 0 && x < VEL && y < VEL && !navstiveno[x][y]) {
  6.         navstiveno[x][y] = true;
  7.         printf("%d, %d\n", x, y);
  8.         tiskniDalsiPoziceKone(x - 1, y - 2, navstiveno);
  9.         tiskniDalsiPoziceKone(x + 1, y - 2, navstiveno);
  10.         tiskniDalsiPoziceKone(x - 1, y + 2, navstiveno);
  11.         tiskniDalsiPoziceKone(x + 1, y + 2, navstiveno);
  12.         tiskniDalsiPoziceKone(x - 2, y + 1, navstiveno);
  13.         tiskniDalsiPoziceKone(x + 2, y + 1, navstiveno);
  14.         tiskniDalsiPoziceKone(x - 2, y - 1, navstiveno);
  15.         tiskniDalsiPoziceKone(x + 2, y - 1, navstiveno);
  16.     }
  17. }
  18. int main() {
  19.     bool pole[VEL][VEL];
  20.     for (int i = 0; i < VEL; i++)
  21.         for (int j = 0; j < VEL; j++) pole[i][j] = false;
  22.     tiskniDalsiPoziceKone(4, 3, pole);
  23.     for (int i = 0; i < VEL; i++) {
  24.         for (int j = 0; j < VEL; j++)
  25.             if (pole[i][j]) printf("X");
  26.             else printf(".");
  27.         printf("\n");
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement