标签:[] return 程序 条件 == static 递归调用 ring str
2,f(n)=f(n-1)+f(n-2) f(0)=2 f(1)=3 ,用程序求得f(40)
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 res = F(40);
Console.WriteLine(res);
int res2 = F(2);
Console.WriteLine(res2);
}
标签:[] return 程序 条件 == static 递归调用 ring str
原文地址:https://www.cnblogs.com/wuxiaohui1983/p/9973186.html