首页 > 其他 > 详细

递归的基本练习

时间:2016-05-14 06:37:31      阅读:263      评论:0      收藏:0      [点我收藏+]

        做梦N层
        static void Main(string[] args)
        {
            Test(1);
        }
        static void Test(int n)
        {
            if (n > 10)
            {
                return;
            }
            Console.WriteLine("正在做第{0}层梦", n);
            Test(n + 1);
            Console.WriteLine("第{0}层梦醒了", n);
        }

猴子吃桃子,每天吃一半然后扔掉一个,问第一天有多少

        static void main(string[] args)
        {
            program hanshu = new program();
            int a = taozi(1);
            console.writeline(a);
        }
        static int taozi(int day)
        {
            if (day == 7)
            {
                return 1;
            }
            int n = (taozi(day + 1) + 1) * 2;
            return n;
        }

 

递归的基本练习

原文:http://www.cnblogs.com/UC0079/p/5491759.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!