当前位置: 移动技术网 > IT编程>开发语言>.net > C#递归例程

C#递归例程

2018年06月10日  | 移动技术网IT编程  | 我要评论

桑叶的药用价值,h漫画图,人物描写

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp1   //函数的递归调用
{
//F(n)= F(n-1)+F(n-2)... F(1)=3; F(0)=2; 求F(40)  
    class Program
    {
        static int F(int n)
        {
            if (n == 0) return 2;  //递归终止的条件
            if (n == 1) return 3;
            return F(n - 1) + F(n - 2);
        }
        static void Main(string[] args)
        {
            int res1= F(40);
            Console.Write(res1);           
            int res2 = F(2);
            Console.Write(res2);
            Console.ReadKey();
        }
    }
}

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网