当前位置:网站首页>C output Fibonacci sequence

C output Fibonacci sequence

2022-07-23 12:59:00 Amateur visionary

One 、 What is Fibonacci series

Fibonacci sequence (Fibonacci sequence), Also called golden section series 、 Because mathematician Leonardo · Fibonacci (Leonardoda Fibonacci) Take rabbit breeding as an example , It is also called “ Rabbit Series ”

Two 、 Fibonacci sequence definition :

Simply speaking , Fibonacci sequence refers to a sequence like this 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89…
That is, the sequence from the first 3 A start , Each of these terms is equal to the sum of the first two terms .

3、 ... and 、 Use C# Realization of Fibonacci series

When we fully understand the definition of Fibonacci sequence , Then it can be implemented in programming language ( Sample selection C# Realize the output Fibonacci sequence , And press 5 That's ok 4 Column mode output )

using System;

namespace fibonacci
{
    
    class Program
    {
    
        static void Main(string[] args)
        {
    
            int a = 1;
            int b = 1;
            int c = 0;
            Console.WriteLine(" Fibonacci sequence :");
            for(int i=1; i<=5; i++)
            {
    
                for (int j=1; j<= 4; j++)
                {
    
                    Console.Write("{0}\t", a);
                    c = a + b;
                    a = b;
                    b = c;
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }
    }
}

原网站

版权声明
本文为[Amateur visionary]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230540375537.html