码迷,mamicode.com
首页 > Windows程序 > 详细

C#迭代器实现斐波那契数列

时间:2020-04-06 15:52:23      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:斐波那契   for   style   col   bsp   数列   count   rev   斐波那契数列   

 static IEnumerable<int> Fibs(int count)
        {
            for (int i = 0,prevFib=1,curFib=1; i < count; i++)
            {
                yield return prevFib;
                int newFib = prevFib + curFib;
                prevFib = curFib;
                curFib = newFib;
            }
        }

 

C#迭代器实现斐波那契数列

标签:斐波那契   for   style   col   bsp   数列   count   rev   斐波那契数列   

原文地址:https://www.cnblogs.com/aqgy12138/p/12642189.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!