fibonacci Numbers
James Davies
jrbd at craycos.com
Sat Apr 13 09:37:15 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).
Well, this program only prints the final answer, and doesn't find the
primes, but you should be able to modify it to do those things.
Usage: "a.out N" prints the Nth fibonacci number.
Good luck!
-- jd
p.s. What can I say, it's Friday (although not April 1 any more)...
------------ %< cut here ----------------
#define A atoi
#define E exit
#define I int
#define O main
#define U printf
#define Y char **
#define W return
I O(c,v)I c;Y v;{W(v&&((c<2)?(U("?\n"),E(1)):1))?(U("%d\n",O(A(*++v)+1,(Y)0)-2),
0):((c>3)?O(c-1,(Y)0)+O(c-2,(Y)0)-2:3);}
More information about the Comp.lang.c
mailing list