Wednesday 20 November 2013

C# : Fibonacci Code

The below code gives the Fibonacci series of numbers in C# for n number of terms :
using System;
class Program
{
    public static int Fibonacci(int n)
    {
 int a = 0;
 int b = 1;
 // In N steps compute Fibonacci sequence iteratively.
 for (int i = 0; i < n; i++)
 {
     int temp = a;
     a = b;
     b = temp + b;
 }
 return a;
    }

    static void Main()
    {
 for (int i = 0; i < 15; i++)
 {
     Console.WriteLine(Fibonacci(i));
 }
    }
}

Output :

1 1 2 3 5 8 13

To know about the Fibonacci Series in detail and also to know the codes of the Fibonacci Series in various other programming languages Click Here
If the above link doesn't work go to this URL :
http://gappcode.blogspot.in/2013/11/fibonacci-series.html

No comments:

Post a Comment