home *** CD-ROM | disk | FTP | other *** search
-
- The Fib Benchmark
- C Compiler Analysis
- February 1985 COMPUTER LANGUAGE
-
-
- /* Fibonacci Number Generator in C */
- #include "STDIO.H"
- #define NTIMES 10 /* number of times to computer Fibonacci value */
-
- #define NUMBER 24 /* biggest that can be computed in 16 bits */
-
-
- void main() /* compute Fibonacci value */
- {
- int i;
- unsigned value, fib();
-
- printf("%d iterations: ", NTIMES);
- for (i = 1; i <= NTIMES; i++)
- value = fib(NUMBER);
- printf("Fibonacci(%d) = %u.\n", NUMBER, value);
- exit(0);
- }
-
- unsigned fib(x) /* compute Fibonacci number recursively */
- int x;
- {
-
- if (x > 2)
- return (fib(x - 1) + fib(x - 2));
- else return (1);
- }