#include #include #include int main (int argc, char **argv); int PrintFibs (int n); int PrintFibLoop (int n, int i); int fib (int i); int goodfib (int i); int main (int argc, char **argv) { return PrintFibs (1000000); } //In C, the main returning 0 means the program ended normally. //You should strive to have the main return 0, except under //certain specific and unusual circumstances. I could say //return (PrintFibs(50),0); but I don't have to, since my //PrintFibs method is going to return 0 anyway. int PrintFibs (int n) { //This will print the first n Fibonacci numbers return PrintFibLoop (n,1); } int PrintFibLoop (int n, int i) { //n is the total number of fibs I want to print. i is the one I'm printing now. return (printf("fib(%d) = %d\n",i,goodfib(i)),(n==i)?0:PrintFibLoop(n,i+1)); } int fib (int i) { return ((i<=1)?i:fib(i-1)+fib(i-2)); } int goodfib (int i) { return ((i<=1)?i:goodfibloop(0,1,2,i)); } int goodfibloop (int x, int y, int n, int i) { //x and y are the two preceding fib numbers, i is the one I want //to compute, and n is the one I'm computing now int t; return (t=x+y,(n==i)?t:goodfibloop(y,t,n+1,i)); }