首页 > 编程语言 > 详细

斐波那契数组-递归和循环实现

时间:2017-09-15 00:22:39      阅读:261      评论:0      收藏:0      [点我收藏+]

static void Main(string[] args)
{
Console.WriteLine(getnumfor(100));
Console.ReadKey();
}
static long getnum(long index)
{
if (index==1||index==2)
{
return 1;
}
else
{
return getnum(index - 1) + getnum(index - 2);
}
}
static long getnumfor(long index)
{
if (index == 1 || index == 2)
{
return 1;
}
else
{
long one = 1; long two = 1;
for (long i = 3; i <= index; i++)
{
if (i == 3)
{
one = 1;
two = 1;
}
else
{
long temp = one;
one = two;
two = temp + two;
}
}
return one + two;
}
}

斐波那契数组-递归和循环实现

原文:http://www.cnblogs.com/zzfstudy/p/7524039.html

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