085.百钱百鸡问题

Posted 程序员编程指南

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了085.百钱百鸡问题相关的知识,希望对你有一定的参考价值。

#include<stdio.h>
void main()

    int x,y,z,j=0;
    clrscr();
    puts("************************************************");
    puts("*      This program is to solve Problem of     *");
    puts("*           Hundred Yuan Hundred Fowls.        *");
    puts("*  Which is presented by Zhang Qiujiang,       *");
    puts("* a Chinese ancient mathematician, in his work *");
    puts("* Bible of Calculation: 5 Yuan can buy 1 cock, *");
    puts("* 3 Yuan can buy 1 hen, 1 Yuan buy 3 chickens, *");
    puts("* now one has 100 Yuan to buy 100 fowls, the   *");
    puts("* question is how many cocks, hens, chickens   *");
    puts("* to buy?                                      *");
    puts("************************************************");
    printf("\\n The possible plans to buy 100 fowls with 100 Yuan are:\\n\\n");
    for(x=0;x<=20;x++)               /*外层循环控制鸡翁数*/
        for(y=0;y<=33;y++)           /*内层循环控制鸡母数y在0~33变化*/
        
            z=100-x-y;             /*内外层循环控制下,鸡雏数z的值受x,y的值的制约*/
            if(z%3==0&&5*x+3*y+z/3==100)
                                   /*验证取z值的合理性及得到一组解的合理性*/
                printf("%2d: cock=%2d hen=%2d chicken=%2d\\n",++j,x,y,z);
	
    puts("\\n Press any key to quit...");
    getch();

以上是关于085.百钱百鸡问题的主要内容,如果未能解决你的问题,请参考以下文章

百钱百鸡算法优化

C语言程序设计百钱买百鸡(百钱百鸡,百鸡问题)!

百钱百鸡的python算法

百钱百鸡,用高中数学优化算法

百钱买百鸡

算法百钱百鸡