Advertisement
mbah_bejo

labirin

Nov 5th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. int n;
  3.  
  4. int find( int lab[n][n], int posx, int posy)
  5. {
  6.     if(posx==n-1 && posy==n-1)
  7.     {
  8.         printf("Ada");
  9.     }
  10.     else{
  11.    
  12.    
  13.     //bawah
  14.     if(lab[posx+1][posy]==1) {
  15.         lab[posx][posy]=0;
  16.         find(lab,posx+1,posy);
  17.         return;
  18.     }
  19.     //kanan
  20.     else if(lab[posx][posy+1]==1) {
  21.         lab[posx][posy]=0;
  22.         find(lab,posx,posy+1);return;
  23.     }
  24.     //kiri
  25.     else if(lab[posx][posy-1]==1) {
  26.         lab[posx][posy]=0;
  27.         find(lab,posx,posy-1);return;
  28.     }
  29.     //atas
  30.     else if(lab[posx-1][posy]==1) {
  31.         lab[posx][posy]=0;
  32.         find(lab,posx-1,posy);return;
  33.     }
  34.     else printf("Tidak Ada");
  35.    
  36.    
  37. }
  38.     //else return;
  39. }
  40. int main()
  41. {
  42.    
  43.     int i,j,tanda;
  44.    
  45.     scanf("%d",&n);
  46.     int lab[n][n];
  47.     for(i=0;i<n;i++)
  48.     {
  49.         for(j=0;j<n;j++)
  50.         {
  51.             scanf("%d",&lab[i][j]);
  52.         }
  53.     }
  54. //  tanda=
  55.     find(lab,0,0);
  56. //  printf("%d",tanda);
  57. //  (tanda==1) ? printf("Ada\n") : printf("Tidak Ada\n");
  58.    
  59.     return 0;  
  60. }
  61.  
  62. /*\
  63. 1  0  0  0
  64. 1  1  0  0
  65. 0  1  0  0
  66. 0  1  1  0
  67. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement