Home » Archimedes archive » Micro User » MU 1991-09.adf » PD-Stuff » FracTrace/FTS-Files/Factorial

FracTrace/FTS-Files/Factorial

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Micro User » MU 1991-09.adf » PD-Stuff
Filename: FracTrace/FTS-Files/Factorial
Read OK:
File size: 00B4 bytes
Load address: 0000
Exec address: 0000
File contents
\ Factorial
\ Calculates the factorial of n

var n,factorial,this           

n=6
factorial=1
if n>1
 for this=n to 1 by -1
  factorial=factorial*this
 endfor
endif
show factorial
00000000  5c 20 46 61 63 74 6f 72  69 61 6c 0a 5c 20 43 61  |\ Factorial.\ Ca|
00000010  6c 63 75 6c 61 74 65 73  20 74 68 65 20 66 61 63  |lculates the fac|
00000020  74 6f 72 69 61 6c 20 6f  66 20 6e 0a 0a 76 61 72  |torial of n..var|
00000030  20 6e 2c 66 61 63 74 6f  72 69 61 6c 2c 74 68 69  | n,factorial,thi|
00000040  73 20 20 20 20 20 20 20  20 20 20 20 0a 0a 6e 3d  |s           ..n=|
00000050  36 0a 66 61 63 74 6f 72  69 61 6c 3d 31 0a 69 66  |6.factorial=1.if|
00000060  20 6e 3e 31 0a 20 66 6f  72 20 74 68 69 73 3d 6e  | n>1. for this=n|
00000070  20 74 6f 20 31 20 62 79  20 2d 31 0a 20 20 66 61  | to 1 by -1.  fa|
00000080  63 74 6f 72 69 61 6c 3d  66 61 63 74 6f 72 69 61  |ctorial=factoria|
00000090  6c 2a 74 68 69 73 0a 20  65 6e 64 66 6f 72 0a 65  |l*this. endfor.e|
000000a0  6e 64 69 66 0a 73 68 6f  77 20 66 61 63 74 6f 72  |ndif.show factor|
000000b0  69 61 6c 0a                                       |ial.|
000000b4