C# Program to Generate Fibonacci Series

Introduction :

In case of fibonacci series, next number is the sum of previous two numbers for example 0, 1, 1, 2, 3, 5, 8, 13, 21 etc. The first two numbers of fibonacci series are 0 and 1.

Here is source code of the C# program which generates a Fibonacci series.The C# program is successfully compiled and executed with Microsoft Visual Studio.The program output is also shown below.

C# Program to Generate Fibonacci Series

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

namespace Fibonancy_series
{
    class Program
    {
        public static int fibonancy(int n)
        {
            int a = 0;
            int b = 1;
            for (int i = 0; i < n; i++)
            {
              int  temp = a;
                a = b;
                b = temp + b;
            }
            return a;
        }
        static void Main()
        {
            for (int i = 0; i < 15; i++)
            {
                Console.WriteLine(fibonancy(i));
                Console.ReadLine();
             }
         }
  }

OutPut of Program :

C# Program to Generate Fibonacci Series

 

Learn Recommended posts :

Leave a Reply

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