Xref: utzoo sci.math:16682 comp.lang.c:38202 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!pikes!aspen.craycos.com!jrbd From: jrbd@craycos.com (James Davies) Newsgroups: sci.math,comp.lang.c Subject: Re: fibonacci Numbers Keywords: Fibonacci Numbers - routines? Message-ID: <1991Apr12.233715.665@craycos.com> Date: 12 Apr 91 23:37:15 GMT References: <1991Apr12.051844.15063@milton.u.washington.edu> Organization: Cray Computer Corporation Lines: 24 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). 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);}