fibonacci Numbers

Roger A. Hurwitz hurwitz at enuxha.eas.asu.edu
Sat Apr 13 16:01:45 AEST 1991


In article <1991Apr12.051844.15063 at milton.u.washington.edu>, amigo at 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 <math.h>
#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.  =^) 



More information about the Comp.lang.c mailing list