{============================================================== iterativeFib.p Started by Jeff Ondich on 10/23/96 Last modified 10/23/96 This program computes Fibonacci numbers iteratively. ==============================================================} program fib(input,output); var N : integer; {============================================================== Fibonacci returns the nth Fibonacci number. ==============================================================} function Fibonacci( n : integer ) : integer; var new, current, previous : integer; begin previous := 1; current := 1; while n > 2 do begin new := current + previous; previous := current; current := new; n := n - 1 end; Fibonacci := current end; {============================================================== Main program ==============================================================} begin write( 'N = ' ); readln( N ); writeln( 'The ', N, 'th fibonacci number is ', Fibonacci(N) ) end.