Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Prog challenge#1 - diff

By: snarez on Feb 10th, 2012  |  syntax: C  |  size: 0.44 KB  |  views: 443  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. int main(){
  3.   int high=100, low=1, guess=0, count=0;
  4.   char answer;
  5.  
  6. while( !count++ && printf("Choose a number [%d, %d] and I'll try to guess it\n", low, high) && 0 || (guess=(high+low)/2) && printf("Is it %d? (y)es, too (h)igh,  too (l)ow\n", guess) && scanf("%c", &answer) && getchar() && ( (answer^'y')?( (answer^'h')?(low=guess):(high=guess) ) : printf("I win, in only %d guesses!\n", count) && 0 ) ) {}
  7.  
  8.   return 0;
  9. }