#!/usr/bin/bc /* Son of Fibonacci * * This file defines the function fib(n). * Run the program, then type fib(42) (for example) * You can calculate as many fibonacci numbers as you like. When you've finished, type quit. * * (c) 2013 D. Haworth */ define fib(n) { ff[0]=1 ff[1]=1 if ( n < 3 ) { f = ff[n-1] } else { i = 3 while ( i <= n ) { f = ff[0] + ff[1] ff[0] = ff[1] ff[1] = f i += 1 } } return (f) }