How to buy a chicken for a hundred dollars
In the fifth century of money, Zhang qiujian, a Chinese ancient mathematician, put forward the "Hundred rooster problem" in the book "computing classics": A rooster worth five yuan and a rooster worth three yuan, three birds worth one. I want to buy a chicken for a hundred dollars. What are the geometric aspects of chicken Weng, chicken mother, and chicken chicks?
Analysis: assume there are X rooster, y hen, and Z chicks. That X + Y + z = 100, and the price is 5 * x + 3 * Y + z/3 = 100. You only need to satisfy the number of the two equations above. We can use C language 3 to repeat all the answers.
However, the number of chickens is a positive integer, and z/3 may produce decimals. Therefore, you may wish to set the money used to buy a chicken as a variable.
Set the number of brokers to int cock, the number of hens to cola, and the money used to buy chicks to p_chickens;
Also, the analysis equation shows that the number of rooster is <20, the number of hens is <= 33, and the money used to buy chicks is p_chickens;
So the program is as follows:
# Include <stdio. h> int main (void) {int C; // Number of cocks int forward; // Number of hens int p_chickens; // For (C = 0; C <20; C ++) for (cost = 0; Cost <33; Cost ++) for (p_chickens = 0; p_chickens <33; p_chickens ++) if (5 * C + 3 * queues + p_chickens = 100) & (C + rooster + 3 * p_chickens = 100) printf ("rooster has % d, hen has % d, and chicken has % d only \ n ", c, counts, 3 * p_chickens); Return 0 ;}
The answer is:
If the number of cocks cannot be 0, remove the first answer.