递归-波那挈数

{
    /// <summary>
    /// 费波那挈数 的摘要说明。
    /// </summary>
    public class 费波那挈数
    {
        public static int 费波那挈数计算(int i)
        {
            if(i<0)
            {
                //Console.Write("此数字没有费波那挈数!");
                return 0;
            }
            if(i==1||i==2)
            {
                //Console.Write("此数的费波那挈数为:{0}",1);
                return 1;
            }
            else
            {
                return 费波那挈数计算(i-1)+费波那挈数计算(i-2);
            }
        }
    }
    public class Client
    {
        [STAThread]
        public static void Main(string[] t)
        {
            int i=Convert.ToInt32(Console.ReadLine());
            Console.Write("{0}的费波那挈数为:{1}",i,费波那挈数.费波那挈数计算(i));
            Console.ReadLine();
        }
    }

}

posted @ 2008-02-20 19:02  稽首本然  阅读(94)  评论(0编辑  收藏  举报