Fibonacci Series C#

A c sharp program to print the fibonacci series. A Fibonacci number is a sequence of numbers in which each Fibonacci number is formed by adding the two numbers before it. It denotes that the next number in the series is the result of adding two previous ones. Let’s use 0 and 1 for the first two integers in the series. We get the third number as 1 by adding 0 and 1.

using System; 
public class main
{
public static void Main(string[] args)
{
int n1=0,n2=1,n3,i,number;
Console.Write("Enter the number");
number = int.Parse(Console.ReadLine());
Console.Write(n1+" "+n2+" ");
for(i=2;i<number;++i)
{
n3=n1+n2;
Console.Write(n3+" ");
n1=n2;
n2=n3;
}
}
}

 

Output:

Enter the number5
0 1 1 2 3

Similar Programs