7+ C Sharp Programs to Print Fibonacci Series

This post contains a total of 7+ C Sharp Program Examples with Source Code to Print Fibonacci Series. All these Fibonacci Series programs are made using C Sharp.

You can use the source code of these examples with credits to the original owner.

Related Posts

C Sharp Programs to Print Fibonacci Series

1. By Kamlesh Kumar

Made by Kamlesh Kumar. Basic Fibonacci series Program. Source

Enter the number of elements: 0 1 1 2 3 5 8 13 21 34
using System;  
  public class Fibonacci 
   {  
     public static void Main(string[] args)  
      {  
         int n1=0,n2=1,n3,i,number;    
         Console.Write("Enter the number of elements: ");    
         number = int.Parse(Console.ReadLine());  
         Console.Write(n1+" "+n2+" "); //printing 0 and 1    
         for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed    
         {    
          n3=n1+n2;    
          Console.Write(n3+" ");    
          n1=n2;    
          n2=n3;    
         }    
      }  
   }  

2. By creativecub

Made by creativecub. C Sharp Program to Print Fibonacci Series of Given Numbers. Source

Enter the part number: 
0
1
1
2
3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace CreativeCub
{
    class Program
    {
        public static void Main()
        {
            int n;
            int a = 0;
            int b = 1;
 
            Console.WriteLine("Enter the part number: ");
            n = int.Parse(Console.ReadLine());
 
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(a);
                int temp = a;
                a = b;
                b = temp + b;
            }
 
            Console.Read();
        }
    }
}

3. By Justin Kindrix

Made by Justin Kindrix. Source

How many numbers of the Fibonacci series would you like to print?

20
Here are the requested numbers:

0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FibonacciTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // User instruction
            Console.WriteLine("How many numbers of the Fibonacci series would you like to print?\n");
            
            // Parse input as a double
            double n = Double.Parse(Console.ReadLine());

            // Clear the console display (Not working in SoloLearn)
            //Console.Clear();

            // Print 'n' numbers of the Fibonacci series
            // (Change to the second argument to 1 to start the series at the number 1 instead of 0)
            Fibonacci(n, 0);
        }
        
        // This Fibonacci() method will write out 'n' numbers of the Fibonacci series to the console using an iterative method
        public static void Fibonacci(double numbers, double startWith)
        {
            double firstNumber = 0, // First number in the series
                secondNumber = 1, // Second number
                nextNumber; // A placeholder for the result of the previous two numbers

            Console.WriteLine("Here are the requested numbers:\n");

            // Input validation for the second parameter
            // (Only allow the numbers 0 or 1)
            try
            {
                switch (startWith)
                {
                    case 0:
                        Console.WriteLine(0);
                        break;
                    case 1:
                        break;
                    default:
                        throw new ArgumentException();
                }
            }
            catch (ArgumentException)
            {
                // Console.Clear() is not working in SoloLearn
                //Console.Clear();
                Console.WriteLine("Second argument can only be 0 or 1\n\nPlease try again...");
                return;
            }

            for (double i = 1; i <= numbers; i++)
            {
                Console.WriteLine(secondNumber);

                nextNumber = firstNumber + secondNumber;
                firstNumber = secondNumber;
                secondNumber = nextNumber;
            }
        }
    }
}

4. By Jayvee Camua

Made by Jayvee Camua. Source

1
1
2
3
5
8
13
21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
	class Program
	{
		static void Main(string[] args)
		{
			int a=1;
            int b=1;
            int c=0;
            int range= 0;
            range = Convert.ToInt32(Console.ReadLine());
            for(int x=1; x<=range; x++){
                a=b;
                b=c;
                c=a+b;
             Console.WriteLine(c);
            }
		}
	}
}

5. By Reeba Jomon

Made by Reeba Jomon. Source

enter the limit
1
2
3
5
8
13
21
34
55
89
144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            int n1=1,n2=2,n3=0,num;
            Console.WriteLine ("enter the limit");
            num=Convert.ToInt32(Console.ReadLine());
            Console.WriteLine (n1 );
          Console.WriteLine (n2);
            for(int i=2;i<=num;i++)
            {
                n3=n1+n2;
                Console.WriteLine (n3);
                n1=n2;
                n2=n3;
            }
        }
    }
}

6. By Sanjeev Kumar

Made by Sanjeev Kumar. Fibonacci series Program using array. Source

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Fibonacci_series
{
    class Program
    {
        static void Main(string[] args)
        {
   int num=Convert.ToInt32(Console.ReadLine());
   //num is user input and defines the number of terms in fibonacci series.       
         double[ ] fibonacci_s=new double[num];
         // array to store terms of fibonacci series.
         fibonacci_s[0]=0;
         fibonacci_s[1]=1;
         
         for(int i=2;i<num;i++)
         
          fibonacci_s[i] = fibonacci_s[i-1] +  fibonacci_s[i-2];//generates the terms of series.
         
         foreach(double i in fibonacci_s)
         Console.Write("{0}, ",i);
         Console.WriteLine("\n\nLikes are motivation and not the money\nSo, Plz give an upvote if the code deserves");
        }
    }
}

7. By Ziyua

Made by Ziyua. C Sharp program to print Fibonacci Series from 0 to infinity. Source

0
1
1
2
3
.....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal  g=1,k=1,n;
            Console.WriteLine("0");
            while(g>=0)
            {
                Console.WriteLine(g);
                n=g; g=k; k+=n;
            };
         
          
        }
    }
}

8. By Milan

Made by Milan. Fibonacci series upto 10. Source

0
1
1
2
3
5
8
13
21
34
using System;


namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n1 = 0;
            int n2 = 1;
            int n3 = 0;
            int numberOfTimes = 0;
            int maxNumberOfTimes = 10; // Edit to change the max number of times
            while (numberOfTimes < maxNumberOfTimes) {
                Console.WriteLine(n3);
                n1 = n2;
                n2 = n3;
                n3 = n1 + n2;
                numberOfTimes += 1;
            }
            
        }
    }
}