Fibonacci Series in C#

using System;
public class Fibonacci
{
public static void Main(string[] args)
{
int n1=0,n2=1,n3,i,num;
Console.Write("Enter the Number of Elements: ");
num = 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 Number of Elements: 7
0 1 1 2 3 5 8

Leave a Reply

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