C# Pattern Fibonacci

Bilangan Fibonacci adalah suatu barisan bilangan yang merupakan hasil penjumlahan dua bilangan sebelumnya.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pattern_Fibonacci
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 100; //Ukuran
            int a = 0;
            int b = 1;
            int c = a + b;
            while (c <= n)
            {
                Console.Write(" " + c);
                c = a + b;
                a = b;
                b = c;
            }
            Console.ReadKey(true);
        }
    }
}

Output:

1 1 2 3 5 8 13 21 34 55 89

Leave a Reply

Your email address will not be published. Required fields are marked *