Problem description:
Buy one hundred chickens for one hundred yuan, one rooster for 5 yuan, one hen for 3 yuan, and three chickens for 1 yuan. Ask how many brokers, hens, and chicks can appear in total.
Code implementation:
# Include <stdio. h> </p> <p> int main () <br/> {<br/> int x, y, z, j = 0; <br/> printf ("Folleing are possible plans to buy 100 fowls with 100 Yuan. /n "); <br/> for (x = 0; x <= 20; x ++) /* control the number of brokers in the outer loop */<br/> for (y = 0; y <= (100-5 * x)/3); y ++) /* the inner layer cyclically controls the number of brokers y to 0 ~ (100-5 * x)/3 changes, Here <br/> many programs are written as y <= 33. I personally think This is not the reason for this writing, efficiency problems */<br/> {<br/> z = 100-x-y;/* The number of chicks z is subject to x, y value constraints */<br/> if (z % 3 = 0 & 5 * x + 3 * y + z/3 = 100) <br/>/* Verify the rationality of the z value and the rationality of a group of solutions */<br/> printf ("% 2d: cock = % 2d kernel = % 2d chicken = % 2d/n ", ++ j, x, y, z); <br/>}< br/>}