百钱买百鸡(普通算法)

 private void button2_Click(object sender, EventArgs e)
        {
            int x = 0;
            int y = 0;
            int z = 0;

            for (int i = 1; i < 100; i++)
            {
                for (int j = 1; j < 100; j++)
                {
                    for (int k = 1; k < 100; k++)
                    {
                        if (5 * i + 3 * j + k / 3 == 100 && i + j + k == 100)
                        {
                            x = i;
                            y = j;
                            z = k;
                            MessageBox.Show("公鸡: " + x + "只,母鸡: " + y + "只,小鸡: " + z + "只", "算出来了");
                        }
                    }
                }
            }

posted @ 2012-07-14 15:20  美丽的矩阵  阅读(276)  评论(0编辑  收藏  举报