By 19/12/2013 12 Comments

Example of Fibonacci Sequence in C# using lable and switch statement

What is Fibonacci sequence:

  • In mathematics, the Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers in the following integer sequence:

0,\;1,\;1,\;2,\;3,\;5,\;8,\;13,\;21,\;34,\;55,\;89,\;144,\; \ldots\;

  • Each number in Fibonacci series performs addition with its previous number

Following examples describes the example of Fibonacci series in c# using label and switch statement

using System; // import namespace system for console class

class Fibs
public static void Main() // main method declaration

reset: // define a label text reset:
Console.WriteLine(); // create a new line space
int p , n , fibon , count; // declare 4 local variables of type an integer

count = 1; // assign 1 into count variable
p = -1; // assign -1 into p variable
n = 1; // assign 1 into n variable

Console.Write("\t Enter any number : "); // print line as an output
fibon = int.Parse(Console.ReadLine()); // int.Parse() method are used to convert string into an integer, also read input from an user at run time assign it into fibon variable

Console.Write("\t Fibonacci series of "+fibon+" :");
up: // define label up:
if(count <= fibon) // condition checks if count variable is less or equal

int sum = p + n; // add p+n into sum
p = n; // assign n into p    
n = sum; // assign sum into n
Console.Write(" "+n); // print Fibonacci series
count++; // add 1 value every time into count variable
goto up; // jump back to up label (define above)



Console.Write("\t Continue ? [y/anyKey]: ");
switch (Console.ReadLine()) // read input from user

case "y": // test case value
case "Y":
goto reset; // jump to reset label




Posted in: C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .