Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- static int x,y;
- static int tab[][5] =
- {
- {1, 1, 1, 1, 1},
- {1, 0, 0, 0, 1},
- {1, 0, 1, 0, 1},
- {1, 2, 1, 3, 1},
- {1, 1, 1, 1, 1}
- };
- void up()
- {
- y=y-1;
- tab[y+1][x]=4;
- printf("Up \n");
- }
- void down()
- {
- y=y+1;
- tab[y-1][x]=4;
- printf("Down \n");
- }
- void left()
- {
- x=x-1;
- tab[y][x+1]=4;
- printf("Left\n");
- }
- void right()
- {
- x=x+1;
- tab[y][x-1]=4;
- printf("Right \n");
- }
- int main()
- {
- x=1;
- y=3;
- printf("Starting position: ");
- printf("%d",tab[y][x]);
- int h,k;
- for (h=0;h<5;h++)
- {
- printf("\n");
- for(k=0;k<5;k++)
- printf("%d, ",tab[h][k]);
- }
- printf("\n Way: \n");
- while (tab[y][x]!=3)
- {
- if (tab[y-1][x]==0 || tab[y-1][x]==3)
- {
- up();
- }
- if (tab[y+1][x]==0 || tab[y+1][x]==3)
- {
- down();
- }
- if (tab[y][x-1]==0 || tab[y][x-1]==3)
- {
- left();
- }
- if (tab[y][x+1]==0 || tab[y][x+1]==3)
- {
- right();
- }
- }
- printf("Found the point.");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement