zoukankan      html  css  js  c++  java
  • 斐波那契数

                       斐波那契数:

                1 1 2 3 5 8 13........

                第一项:1;

                第二项:1;

                第三项:第一项+第二项 f(2)+f(1);

                第四项:第三项+第二项 f(3)+f(2);

                第五项:第四项+第三项 f(4)+f(3);

                第n项:f(n-1)+f(n-2);

            static void Main(string[] args)

            {

                int a = num(6);

                Console.WriteLine(a);

                Console.ReadKey();

            }

            public static int num(int n)

            {

                if (n == 1 || n == 2)   

                {

                    return 1;

                }

                else

                {

                    return num(n - 1) + num(n - 2);

                }

            }

  • 相关阅读:
    PHP中关于字符串的连接
    好用的FireFox(FF)插件
    Scripted Operation
    Scripted device
    chgrp chown
    wait_for_devices
    mysql create user
    mysql
    create user mysql
    Inserting/Removing shutters and filters
  • 原文地址:https://www.cnblogs.com/sky-wolf/p/7725438.html
Copyright © 2011-2022 走看看