473,217 Members | 2,114 Online

# FIBONACCI

Hi All,

Can anyone tell about how to create a FIBONACCI series in VB.Net and C#

Veeru

Nov 26 '06 #1
3 11924
Hello veeru,

vHi All,
v>
vCan anyone tell about how to create a FIBONACCI series in VB.Net and
vC#
v>
v>
vVeeru
v>
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 26 '06 #2
Hello veeru,

A little bit better search http://www.google.com/codesearch?as_...n&as_lang=c%23

vHi All,
v>
vCan anyone tell about how to create a FIBONACCI series in VB.Net and
vC#
v>
v>
vVeeru
v>
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 26 '06 #3

"Michael Nemtsev" <ne*****@msn.comwrote in message
news:17***************************@msnews.microsof t.com...
Hello veeru,

A little bit better search

vHi All,
vvCan anyone tell about how to create a FIBONACCI series in VB.Net and
vC#
vvVeeru
v>
While those are correct implementations of the fibonacci sequence (it's a
sequence (http://en.wikipedia.org/wiki/Sequence), not a
series(http://en.wikipedia.org/wiki/Series_...matics%29))the vast
majority are recursive implementations, that because of the limited stack
space, only work for the first few numbers in the sequence, and perform
really poorly.
Here's a little sample with a recursive and an iterative implementation of
fibonacci. Play around with it so see how much better the iterative
implementation is.
class Program
{
static int FibR(int n)
{
if (n < 2)
return 1;
else
return FibR(n - 1) + FibR(n - 2);
}
static long FibI(long n)
{
if (n < 2)
return 1;

long fp = 1;
long fpp = 1;
long f = 0;
for (int i = 2; i < n; i++)
{
f = fp + fpp;
fpp = fp;
fp = f;
}
if (f < 0)
throw new OverflowException();

return f;
}

public static int Main(string[] args)
{
Console.WriteLine(FibI(1000 * 1000 * 1000));
return 0;
}
}
David

Nov 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.