Two-part method
Example: Look at the price of goods
First show a product priced at 999 yuan, the participants to guess the price of the goods. In the process of guessing the price, the referee will give more participants the price, corresponding to the "high" or "low" hint.
Table 1-1 Two-way guess commodity price (640)
Number |
Price range |
Middle Value |
1th time |
0~999 |
500 |
2nd time |
500~999 |
750 |
3rd time |
500~750 |
620 |
4th time |
620~750 |
680 |
5th time |
620~680 |
650 |
6th time |
620~650 |
630 |
7th time |
630~650 |
640 |
//0~999 guess the priceConsole.WriteLine ("Please enter the price of the product:"); intCommoditprices =convert.toint16 (Console.ReadLine ()); Console.WriteLine ("participants:"); intprices=convert.toint16 (Console.ReadLine ()); intI=1; while(true) {i++; if(prices<commoditprices) {Console.WriteLine ("it's low."); Console.WriteLine ("participants:"); Prices=convert.toint16 (Console.ReadLine ()); } Else if(prices>commoditprices) {Console.WriteLine ("High."); Console.WriteLine ("participants:"); Prices=convert.toint16 (Console.ReadLine ()); } Else{Console.WriteLine ("Congratulations, guess right, guess {0} times in total. ", i); Break; }} console.readkey ();
Dichotomy Method C #