Question about "buy a chicken for a hundred dollars"

Source: Internet
Author: User

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/>}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.