for循环语句之兔子生崽

有一对幼兔,幼兔经过一个月长为小兔,小兔经过一个月长为大兔并且生下一对幼兔,而且大兔每月还会生下一对幼兔,问N个月后有多少对兔子

            Console.WriteLine("请输入经过了几个月:");
            int n = Convert.ToInt32(Console.ReadLine());

            int syt = 1, byt = 0;
            int sxt = 0, bxt = 0;
            int sdt = 0, bdt = 0;

            for (int i = 1; i <= n; i++)
            {
                byt = sdt + sxt;
                bxt = syt;
                bdt = sdt + sxt;

                syt = byt;
                sxt = bxt;
                sdt = bdt;
            }

            Console.WriteLine("经过" + n + "个月后:");
            Console.WriteLine("幼兔为:" + byt + "");
            Console.WriteLine("小兔为:" + bxt + "");
            Console.WriteLine("大兔为:" + bdt + "");
            int sum = byt + bxt + bdt;
            Console.WriteLine("兔子总共有:" + sum + "");

            Console.WriteLine("兔子总共有:{0}对,小兔子有{1}对", sum, bxt);

 

posted @ 2015-07-08 23:11  Franky2015  阅读(672)  评论(0编辑  收藏  举报