c# 运用while语句编码

大家好,我学c#的初学者,如何运用while 语句编写鸡兔同笼问题的编码呢?希望可以得到大家的帮助,谢谢

用while只能采用比较笨的方法,如枚举所有情况

建议你采用如下方法,直接可以计算出来

http://wenku.baidu.com/link?url=qYTO9ruD7gaw_f4U8Z6Ay25WerihnLR8kP9vAOKp4wRqcdsY0x3DInt8VAKzHXy6iyE5Bveut999nbDaHQwr_LyROaG1YPuVuXna-l3UbFS

m头,n脚。
1.设鸡和兔同时抬起两只脚,则抬起2m只脚
2.判断 x = (n-2m)/2 是否为正整数,如果为整数则得到兔的数量为x,鸡的数量为 y = m-x
3.否则输入的m和n有误

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChickenAndRabbit
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("请输入头和脚的个数以英文逗号隔开");
String para = System.Console.ReadLine();//获取输入
String[] paras = para.Split(',');//以逗号分开
int head = 0;
int feet = 0;
try
{
head = System.Convert.ToInt32(paras[0]);
feet = System.Convert.ToInt32(paras[1]);
}
catch
{
System.Console.WriteLine("输入错误");
System.Console.ReadKey();//停留在答案界面以便查看结果
}
//计算过程
int chicken = 0;
while (chicken <=head)
{
if (chicken * 2 + (head - chicken) * 4 == feet)//找到答案则输入并返回
{
System.Console.WriteLine("鸡的个数为" + chicken + ",兔子的个数为" + (head - chicken));
System.Console.ReadKey();//停留在答案界面以便查看结果
return;
}
chicken++;
}
System.Console.WriteLine("该问题无解!");//循环结束仍没有找到答案就无解
System.Console.ReadKey();//停留在答案界面以便查看结果
}
}
}