Home > Back-end >  Introduction to your bosses, small white consult a C language problem.
Introduction to your bosses, small white consult a C language problem.

Time:10-07

Using C language implementation guess Numbers game

CodePudding user response:

Only exists in a card, only six combinations, unable to put down to 50
Only exists in two card, only 30 combination, also can't put down to 50,
So, you can define an array of such
Card [6] [5], [4], can put a number of 120

To assign, arranged as shown in figure,
When a user points to a, two, or three CARDS, you can guess what is this number

CodePudding user response:

Small case
The first number on each card 1,2,4,8,16,32
Any number of 1 ~ 63, inevitably can be dissected into the above 6 digits in a number of and
7, for example, can be salvaged for 1 + 2 + 4, so let him in the first, second and third in a
Like: 45, can be decomposed into 32 + 8 + 4 + 1, so it is the first, three, four and six CARDS appear

Loop from 1 to 50, according to the number of each binary form each bit is 1, you know in which a card, thus finish initializing an array of

User input digital, in which the card, just take out the first number on the card, sum them, you know the number is few,


Nothing is so difficult, write their own, there is a problem, asking questions posted code
  • Related