Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void main(void)
- {
- char c;
- int numero=0;
- int num_max=100000;
- int num_min=0;
- int i=0;
- int verifica=0;
- printf("Pensa un numero intero tra %d e %d senza dirlo!Digita s quando lo hai pensato: ",num_min,num_max);
- scanf("%c",&c);
- if (c=='s')
- {
- c=' ';
- for(;;)
- {i=i+1;
- numero=(num_max+num_min)/2;
- printf("Il numero è %d? Scrivi s se ho indovinato altrimenti > se il numero è più grande o < se il numero è più piccolo: ",numero);
- scanf(" %c",&c);
- if (c=='s')
- {
- verifica=1;
- break;
- }
- else if (c=='>')
- {
- if(numero==(num_max-1))
- {
- printf("Il numero è %d!\n",num_max);
- verifica=1;
- break;
- }
- else num_min=numero;
- }
- else if (c=='<') num_max=numero;
- else break;
- }
- }
- if(verifica==1) printf("L'ho indovinato in %d mosse\n",i);
- else printf("C'è stato un errore\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement