现在的位置: 首页 > 综合 > 正文

C#百元白鸡问题

2014年02月22日 ⁄ 综合 ⁄ 共 327字 ⁄ 字号 评论关闭
using System;
using System.Collections.Generic;
using System.Text;

namespace lession5
{
    class Program
    {
        static void Main(string[] args)
        {
           
            //百元白鸡问题
            //I+J+K=100; 5*I+3*j+K/3=100;
            int gj, mj, xj;
          
            for ( gj = 0; gj <= 20; gj++)
            {
                for (mj = 0; mj < 33; mj++)
                {
                    xj = 100 - mj - gj;
                    if ((5 * gj + 3 * mj + xj / 3.0)== 100)
                    {
                        Console.WriteLine("公鸡:{0}母鸡:{1}小鸡:{2}",gj,mj,xj);
                    }
                }
            }

            Console.ReadLine();
       }
    }
}

抱歉!评论已关闭.