zoukankan      html  css  js  c++  java
  • 斐波那契数组-递归和循环实现

    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;
        }
    }
  • 相关阅读:
    数组
    2017.3.20for
    PHP基础2
    php基础1
    触发器
    SQL储存过程
    范式
    时间戳
    主键和外键
    15 大图轮播
  • 原文地址:https://www.cnblogs.com/zzfstudy/p/7524039.html
Copyright © 2011-2022 走看看