next up previous contents
Next: The Perl implementation Up: The Fibonacci calculator Previous: The Fibonacci calculator   Contents

The C implementation

This code was compiled with the EGCS 1.1.2 compiler using the following compilation options: -O6 -mcpu=i686

#include <stdio.h>

int fib(int n)
{
  if(n > 2)
    return fib(n-1) + fib(n-2);
  return n;
}

int main(int argc, char** argv)
{
  int res;
  printf("Calculating fib(30)...");
  fflush(stdout);
  res = fib(30);
  printf("done.\n"); 
  printf("fib(30) = %i\n", res);
}




1999-08-09