469,267 Members | 1,055 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

FIBONACCI

Hi All,

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

Thanks in Advance,

Veeru

Nov 26 '06 #1
3 11657
Hello veeru,

http://www.google.com/codesearch?q=Fibonacci+C%23&hl=en

vHi All,
v>
vCan anyone tell about how to create a FIBONACCI series in VB.Net and
vC#
v>
vThanks in Advance,
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>
vThanks in Advance,
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
http://www.google.com/codesearch?as_...n&as_lang=c%23

vHi All,
vvCan anyone tell about how to create a FIBONACCI series in VB.Net and
vC#
vvThanks in Advance,
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));
Console.ReadKey();
return 0;
}
}
David

Nov 26 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by dleecurt | last post: by
reply views Thread by Alex Vinokur | last post: by
5 posts views Thread by Lance | last post: by
5 posts views Thread by Niks | last post: by
14 posts views Thread by felixnielsen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.