Guest User

recursive 3b

a guest
Dec 31st, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int array[3] = {0,0,1};
  5.  
  6. void delay()
  7. {
  8.     for(int i=0;i<1000000;i++)
  9.         for(int j=0;j<100;j++);  
  10. }
  11.      
  12. void view(int j)
  13. {
  14.        delay();
  15.        system("cls");
  16.  
  17.        printf("-------\n|");
  18.        for(int i=0;i<3;i++)
  19.        {
  20.             if(i == j)
  21.                 printf("#|");    
  22.             else if(array[i]==1)
  23.                 printf("G|");
  24.             else if(array[i]==0)
  25.                 printf(" |");
  26.        }
  27.        printf("\n-------\n");
  28. }
  29.                
  30. bool find_1(int j)
  31. {
  32.     view(j);
  33.     if(j < 3)
  34.     {
  35.         if(array[j] == 1)  
  36.         {
  37.             array[j] = 0;
  38.             view(j);
  39.             return 1;
  40.         }
  41.         else
  42.         {
  43.  
  44.             int temp = find_1(j+1);
  45.             view(j);
  46.             return temp;
  47.         }
  48.     }
  49.     else
  50.     {
  51.         view(j);
  52.         return 0;  
  53.     }
  54. }
  55.  
  56. int main()
  57. {
  58.    if(find_1(0))
  59.     printf("Got Gold\n");
  60.    else
  61.     printf("Got Nothing\n");
  62.    system("pause");
  63.    return 0;    
  64. }
Advertisement
Add Comment
Please, Sign In to add comment