Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!asuvax!enuxha!hurwitz From: hurwitz@enuxha.eas.asu.edu (Roger A. Hurwitz) Newsgroups: comp.lang.c Subject: Re: fibonacci Numbers Summary: Fibonacci Formula Keywords: Fibonacci Numbers - routines? Message-ID: <3019@enuxha.eas.asu.edu> Date: 13 Apr 91 06:01:45 GMT References: <1991Apr12.051844.15063@milton.u.washington.edu> Organization: Arizona State University, Tempe, AZ Lines: 22 In article <1991Apr12.051844.15063@milton.u.washington.edu>, amigo@milton.u.washington.edu (The Friend) writes: > > Can someone send me source code for a routine to calculate > Fibonacci numbers to _x_ (x being input from user)? Additionally it'd > be great if this found the PRIME numbers in the set. It could print its > results as it went through (if that makes it any easier). I picked up the following nifty formula from somewhere for calculating any Fibonacci number in the sequence: #include #define SQRT5 2.2360679775 main() { double x, fib; . . fib = (pow((1.0 + SQRT5) / 2.0, x) - pow((1.0 - SQRT5) / 2.0, x)) / SQRT5; } I'm afraid I can't help you on the prime number question. =^)