In this blog we will create a program in c# for printing Fibonacci series till N level.


What is Fibonacci Number?

A Fibonacci number is a series of numbers in which each Fibonacci number is obtained by adding the two preceding numbers. It means that the next number in the series is the addition of two previous numbers. Let the first two numbers in the series is taken as 0 and 1. By adding 0 and 1, we get the third number as 1. Then by adding the second and the third number (i.e) 1 and 1, we get the fourth number as 2, and similarly, the process goes on. 






Code Explanation:

  • Here first we declare four int variable num1, num2, num3, and num4 and assign num1 0 and num2 to 2.
  • Then we print message for user.
  • In next line we get input from user and convert that number into integer.
  • Then print first two number which is 0 and one before loop.
  • Next iterate loop from 2 to the number which user enter. Why from 2 because above we print 0 and 1.
  • In loop we assign num1 and num2 to num3 and print num3.
  • Then assign num2 to num1 and num3 to num3.
  • Then We use the Console.ReadKey() method to read any key from the console. By entering this line of code, the program will wait and not exit immediately. The program will wait for the user to enter any key before finally exiting. If you don't include this statement in code, the program will exit as soon as it is run.

Output

Fibonacci Series In C# Console Application By Yogeshkumar Hadiya

Fibonacci Series In C# Console Application By Yogeshkumar Hadiya