Fibonacci





5
Date Submitted Tue. May. 29th, 2007 5:57 PM
Revision 1 of 1
Beginner ashraf_eme
Tags "ASP.NET 2.0" | "CSharp" | Fibonacci
Comments 0 comments
That is, after two starting values, each number is the sum of the two preceding numbers. The first Fibonacci numbers , also denoted as Fn, for n = 0, 1, … , are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811…
this is One line function to get the sequance.


public static int Fibonacci(int x) {
  return (x == 0 || x == 1) ? x : Fibonacci(x - 1) + Fibonacci(x - 2);
 }

 

ashraf ezzat

Comments

There are currently no comments for this snippet.

Voting

Votes Down