Advertisement
Jonas_3k

WRUT 1.0.2

Oct 16th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. #include<stdio.h>
  2. int pot(int i, int x)
  3. {
  4.     if(x ==0 ) return 1;
  5.     else return i*pot(i,x-1);
  6. }
  7.  
  8. main()
  9. {
  10.     int array[10],i=0,x,soma=0;
  11.     char op,ct='i';
  12.  
  13.     do{
  14.         if(ct=='i')
  15.         {
  16.             printf("\nVoce esta pensando num numero impar ?  [S/N]: ");
  17.         }  
  18.         else
  19.         {
  20.             printf("\nConsiderando somente a parte inteira, caso eu o divida por dois o resultado seria impar? [S/N]: ");
  21.             ct='d';
  22.         }
  23.          
  24.         scanf(" %c",&op);
  25.        
  26.         if(op=='s')
  27.         {          
  28.             printf("\nPreciso saber se o resultado desta divisao seria o numero 1 [S/N]: ");
  29.             scanf(" %c",&op);
  30.             if(ct == 'i' && op=='n')
  31.             {
  32.                 printf("Ok, caso eu divida este numero por dois e ");
  33.                 ct = 'f';
  34.             }
  35.            
  36.             if(op=='s')
  37.             {
  38.                 op = 'q';
  39.                 array[i]=1;
  40.             }
  41.             else
  42.             {
  43.                 printf("\nOk, responda a seguinte pergunta. ");
  44.                 ct='f';
  45.                 array[i] = 1;  
  46.             }
  47.         }
  48.        
  49.         else
  50.         {
  51.             if (ct == 'i') ct = 'f';
  52.             else array[i]=0;
  53.         }
  54.  
  55.         i++;
  56.  
  57.     }while(op !='q');
  58.  
  59.     for (x = 0; x < i; x++ ) soma+= array[x]*pot(2,x);
  60.  
  61.     printf("\nVoce estava pensando no numero %d", soma);
  62.     scanf(" %c");
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement