I googled "20q code" and found this: http://mosaic.cnfolio.com/B142LCW2008A197
This version is only for animals but the actual 20 Questions probably has a similar algoritm.
Here is a quick overview of the code I linked:
There are several different answers hard coded into the program. Several TRUE or FALSE attributes are then assigned to them:
#define ANIMALS_LIST "daddylonglegs bee penguin eagle giraffe octopus tiger elephant jellyfish bull \nparrot dolphin python crocodile cat leopard monkey zebra sheep rat \nowl spider frog polarbear snail tortoise rabbit salmon rhino fox"
#define MAMMALS "0 0 0 0 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 1 0 0 0 1 0 0 1 0 1 1"
#define FLYING_ANIMALS "1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
#define WATER_ANIMALS "0 0 1 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 1 0 1 0 1 1 0"
#define BEAK "0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0"
...
As you can see a bee is not mammal but it does fly, etc.
There is an array for each group:
int mammals[ TOTAL_ANIMALS ] = { 0 };
int flying_animals[ TOTAL_ANIMALS ] = { 0 };
int water_animals[ TOTAL_ANIMALS ] = { 0 };
...
When each question is asked:
askUserQuestion( guesses, "\nQuestion %d: Is your animal a mammal? \n", mammals );
The program looks at the definition of the appropriate category and tracks which animal is most likely the one you are thinking of based on the TRUE or FALSE values and your inputed Yes or No answer to the question.
This is done in:
void askUserQuestion( int guessNumber, char* question, int* animalData );