How to use C language to deal with the problem of a hundred dollars and a hundred chickens in calculating Classics
This article mainly introduces how to use C language to deal with the problem of a hundred dollars and a hundred chickens in the calculation classics, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.
1. Problem description
Zhang Qiujian, an ancient Chinese mathematician, put forward a famous "problem of a hundred dollars and a hundred chickens" in his calculation Classics. A rooster is worth five dollars, a hen is worth three, and three chicks are worth one. Now we have to buy a hundred chickens with a hundred dollars. How many cocks, hens and chicks are each?
two。 Analysis of problems
If you only buy cocks for one hundred dollars, you can buy up to 20 cocks, but the title requires you to buy 100 cocks, so the number of cocks is between 0 and 20. By the same token, the number of hens is between 0 and 33. Here, the number of Roosters, hens and chicks is set to cock, hen and chicken, respectively, and the cock+hen+chicken=100 problem is transformed into a problem of solving indefinite equations:
3. Algorithm idea
For the system of indefinite equations, we can use the method of exhaustive loop to solve it. The range of cock is 020, and the available statement for (cock=0; cock)