Providers
Debian Linux
SDF
MinGW-W64
Verizon
Research
Faqs and RFCs
FileSearching
Google
Google Groups
W3Schools Online Web Tutorials
Wikipedia
Multimedia
CTIS
For the Pigs Among Us
Family Photos
My House
My Photos (1999-2002?)
My Photos (2005)
Retro Computers
Minions of Mirth
Main
Criticals
Criticals (Single Player)
Ghaqua
Maps and Points of Interest
Miscellaneous
Monster Templates
Miscellaneous
Area Codes
Bard’s Tale
Dungeons & Dragons Online
My Blog
Quote of the Day
RogueBasin
Slashdot
The Adventuer’s Guild
Weather
GitHub:eprive/Z80-MBC3
Programming
Main
Across
Biorhythm
BMP Chips
Complex Roots
Magic Square
Magic Square(js)
Matrix(js)
More DOS Programs
Roll
Strip Dups (bash)
Wacky Wood-Worker
How To
Enlightenment 0.16.7.2 Startup Patch
How to Create an OS X Iconset
My RedHat Howto
SSH to VMS (Deathrow OpenVMS Cluster)
Tools
Allowable Mortgage Interest
Dates and Mileage
Day of the Year
Fun With Time
Downloads
Educational
Utilities
fibonacci.pas
program recurseFibonacci; Uses sysutils; const MAXFIB = 47; VERSION = 0.1; var i, f, n : longint; TS : TTimeStamp; t : array [0..50] of longint; DONE : Boolean; QUIET : Boolean; VERBOSE : Boolean; TIMING : Boolean; NUMSET : Boolean; code : word; function fibonacci(n : longint): longint; begin (* Return -1 when invalid *) if (n>47) or (n<1) then fibonacci := -1 else if n=1 then fibonacci := 0 else if n=2 then fibonacci := 1 else fibonacci := fibonacci(n-1) + fibonacci(n-2); end; procedure Usage; Begin writeln('Fibonacci - Prints the nth number in the Fibonacci sequence.'); writeln('Michael J. Chappell January 2, 2019'); writeln; writeln('Usage is:'); writeln; writeln(' fibonacci [-h][-q][-t][-v][n]'); writeln; writeln('-h Prints this help message.'); writeln('-q Quiet. Prints the result.'); writeln('-t Prints timing information.'); writeln('-v Prints information from intermediate computations.'); writeln; writeln('n Should be an integer between 1 and 47.'); writeln; writeln('You will be prompted for ''n'' if it is not provided.'); writeln; writeln('fibonacci version ', VERSION:3:1, ' Copyright January 2, 2019 Michael J. Chappell'); writeln; End; begin QUIET := False; VERBOSE := False; TIMING := False; NUMSET := False; DONE := False; for i:=0 to argc-1 do begin if AnsiCompareStr(argv[i],'-q')=0 then QUIET := TRUE; if AnsiCompareStr(argv[i],'-t')=0 then TIMING := TRUE; if AnsiCompareStr(argv[i],'-v')=0 then VERBOSE := TRUE; if AnsiCompareStr(argv[i],'-h')=0 then DONE := True; val(argv[i],n,code); if code=0 then begin NUMSET := True; end; end; { for } if NOT (TIMING or VERBOSE) then QUIET := True; if VERBOSE then QUIET := False; if (NOT NUMSET) and (NOT DONE) then begin writeln('How many numbers in the fibonacci sequence should be output?'); readln(n); end; { if } if (n>MAXFIB) or (n<1) then DONE := TRUE; if (n>0) and (NOT DONE) then begin if VERBOSE then writeln('The first ', n, ' numbers in the Fibonacci sequence are:'); TS := DateTimeToTimeStamp(Now); t[0] := TS.time; for i:= 1 to n do begin f := Fibonacci(i); if f<0 then Usage; if NOT QUIET then begin if TIMING or VERBOSE then write('Fibonacci(',i:2,') = ',f:11, '. '); TS := DateTimeToTimeStamp(Now); t[i] := TS.time; if TIMING then writeln('The computation took ',(t[i] - t[i-1]):5, ' milliseconds.') else writeln; end { if NOT QUIET } else begin if (i=n) then writeln(f); end; end { for } end; { if n>0 and NOT DONE } if DONE then Usage(); end.
This source has been viewed 16 times.
Friday, 6 December 2024
Michael J. Chappell
Contact me at:
mcsuper5@freeshell.org