Fibonacci Sequence Series in C#

The Fibonacci sequence is a series of numbers where a number is found by adding up the two numbers before it. Starting with 0 and 1, the sequence goes 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so forth.

Source Code 

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

namespace evenFibonacci
{
    class Program
    {
        static void Main(string[] args)
        {
            welcomeScrean();
            evenFibonacci();
            int wait = Convert.ToInt32(Console.ReadLine());
        }

        private static void welcomeScrean()
        {
            Console.Write("\a"
            + "\t*******************************************************" + "\n"
            + "\t**                                                   **" + "\n"
            + "\t**                   Welcome To                      **" + "\n"
            + "\t**                                                   **" + "\n"
            + "\t**               Find Even Fibonacci                 **" + "\n"
            + "\t**                                                   **" + "\n"
            + "\t**                 and there sum                     **" + "\n"
            + "\t**                                                   **" + "\n"
            + "\t**                 Program By LEP                    **" + "\n"
            + "\t**                                                   **" + "\n"
            + "\t*******************************************************" + "\n");
        }

        private static void evenFibonacci()
        {
            int num, count = 0;
            long previous = 1, next = 0, sum;
            Console.Write("\t Enter Your Number to Find Fibonacci ");
            num = Convert.ToInt32(Console.ReadLine());

            Console.Write("\n\t First " + num + " Even Fibonacci Numbers Are \n");

            do
            {
                if (previous % 2 == 0)
                {
                    Console.Write("\n\t " + previous + " ");
                    count++;
                }
                sum = previous + next;
                next = previous;
                previous = sum;

            } while (count != num);

        }
    }
}

Output of the Program

C# Program code for Fibonacci sequence series

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment