Write a program in C# to print the Fibonacci series.
Following is the simple C# code :
Following is the simple C# code :
class Lab { static void Main(string[] args) { int i, count, Fib1 = 0, Fib2 = 1, Fib3 = 0; Console.Write("Enter the Fib Limit : "); count = int.Parse(Console.ReadLine()); Console.WriteLine("Fibonacci sequence are "); Console.WriteLine(Fib1); Console.WriteLine(Fib2); for (i = 0; i <= count; i++) { Fib3 = Fib1 + Fib2; Console.WriteLine(Fib3); Fib1 = Fib2; Fib2 = Fib3; } Console.ReadLine(); } }
Output:-
Enter the Fib Limit : 5 Fibonacci sequence are 0 1 1 2 3 5 8 13
No comments:
Post a Comment
Note: only a member of this blog may post a comment.