码迷,mamicode.com
首页 > 其他好文 > 详细

递归的基本练习

时间:2016-05-14 06:40:38      阅读:120      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!