Providers
Debian Linux
SDF
MinGW-W64
Verizon
Research
Search Engines
Bing
DuckDuckGo
Google
Metacrawler
SearX
Miscellaneous
Faqs and RFCs
Open Directory Project
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
factorial.pas
program factorial; Uses sysutils; const MAXFACT = 20; VERSION = 0.1; COPYDATE = 'January 3, 2019'; WEBSITE = 'http://mcsuper5.freeshell.org/programs.html'; var num, f : Int64; HELP : Boolean; QUIET : Boolean; VERBOSE : Boolean; NUMSET : Boolean; code : word; i : Integer; function fact(x : Int64): Int64; begin if x=0 then fact:= 1 else fact := x * fact(x-1); end; procedure Copyright; begin writeln('factorial version ', VERSION:3:1, ' Copyright ', COPYDATE, ' Michael J. Chappell'); writeln('The latest version can be found at: ',WEBSITE); writeln; end; procedure Usage; begin writeln('Factorial - Prints the factorial of an integer between ', '1 and ', MAXFACT, '.'); writeln('Michael J. Chappell ', COPYDATE); writeln; writeln('Usage is:'); writeln; writeln(' factorial [-h][-q][-v][n]'); writeln; writeln('-h Prints this help message.'); writeln('-q Quiet. Prints the result only.'); writeln('-v Verbose. Includes copyright information.'); writeln; writeln('Where ''n'' is an integer between 1 and ', MAXFACT, '.'); writeln('You will be prompted for ''n'' if it is not provided.'); writeln; Copyright; end; procedure printResult(n, f : Int64; QUIET, VERBOSE : Boolean); begin if VERBOSE then Copyright; if QUIET then writeln(f) else writeln(n:2,'! = ',f); end; begin QUIET := False; VERBOSE := False; NUMSET := False; HELP := False; for i:=0 to argc-1 do begin if AnsiCompareStr(argv[i],'-q')=0 then QUIET := TRUE; if AnsiCompareStr(argv[i],'-v')=0 then VERBOSE := TRUE; if AnsiCompareStr(argv[i],'-h')=0 then HELP := True; val(argv[i],num,code); if code=0 then begin NUMSET := True; end; end; { for } if (NOT NUMSET) and (NOT HELP) then begin write('For which number would you like to find the factorial? (1-20) '); readln(num); end; { if } if (num>MAXFACT) or (num<1) then HELP := TRUE; if HELP then Usage else printResult(num, fact(num), QUIET, VERBOSE); end.
This source has been viewed 6 times.
Wednesday, 2 July 2025
Michael J. Chappell
Contact me at:
mcsuper5@freeshell.org