Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int n;
- int find( int lab[n][n], int posx, int posy)
- {
- if(posx==n-1 && posy==n-1)
- {
- printf("Ada");
- }
- else{
- //bawah
- if(lab[posx+1][posy]==1) {
- lab[posx][posy]=0;
- find(lab,posx+1,posy);
- return;
- }
- //kanan
- else if(lab[posx][posy+1]==1) {
- lab[posx][posy]=0;
- find(lab,posx,posy+1);return;
- }
- //kiri
- else if(lab[posx][posy-1]==1) {
- lab[posx][posy]=0;
- find(lab,posx,posy-1);return;
- }
- //atas
- else if(lab[posx-1][posy]==1) {
- lab[posx][posy]=0;
- find(lab,posx-1,posy);return;
- }
- else printf("Tidak Ada");
- }
- //else return;
- }
- int main()
- {
- int i,j,tanda;
- scanf("%d",&n);
- int lab[n][n];
- for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- {
- scanf("%d",&lab[i][j]);
- }
- }
- // tanda=
- find(lab,0,0);
- // printf("%d",tanda);
- // (tanda==1) ? printf("Ada\n") : printf("Tidak Ada\n");
- return 0;
- }
- /*\
- 1 0 0 0
- 1 1 0 0
- 0 1 0 0
- 0 1 1 0
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement