Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. static int x,y;
  5. static int tab[][5] =
  6. {
  7. {1, 1, 1, 1, 1},
  8. {1, 0, 0, 0, 1},
  9. {1, 0, 1, 0, 1},
  10. {1, 2, 1, 3, 1},
  11. {1, 1, 1, 1, 1}
  12. };
  13.  
  14. void up()
  15. {
  16. y=y-1;
  17. tab[y+1][x]=4;
  18. printf("Up \n");
  19. }
  20.  
  21. void down()
  22. {
  23. y=y+1;
  24. tab[y-1][x]=4;
  25. printf("Down \n");
  26. }
  27.  
  28. void left()
  29. {
  30. x=x-1;
  31. tab[y][x+1]=4;
  32. printf("Left\n");
  33. }
  34.  
  35. void right()
  36. {
  37. x=x+1;
  38. tab[y][x-1]=4;
  39. printf("Right \n");
  40. }
  41.  
  42.  
  43.  
  44. int main()
  45. {
  46. x=1;
  47. y=3;
  48.  
  49. printf("Starting position: ");
  50. printf("%d",tab[y][x]);
  51.  
  52. int h,k;
  53.  
  54. for (h=0;h<5;h++)
  55. {
  56. printf("\n");
  57. for(k=0;k<5;k++)
  58. printf("%d, ",tab[h][k]);
  59. }
  60.  
  61. printf("\n Way: \n");
  62.  
  63. while (tab[y][x]!=3)
  64. {
  65. if (tab[y-1][x]==0 || tab[y-1][x]==3)
  66. {
  67. up();
  68. }
  69. if (tab[y+1][x]==0 || tab[y+1][x]==3)
  70. {
  71. down();
  72. }
  73. if (tab[y][x-1]==0 || tab[y][x-1]==3)
  74. {
  75. left();
  76. }
  77. if (tab[y][x+1]==0 || tab[y][x+1]==3)
  78. {
  79. right();
  80. }
  81. }
  82.  
  83. printf("Found the point.");
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement