* * this program computes and prints a table of factorials * for 1 through 'nx' * * it demonstrates a method of manipulating numbers which are * too large for the computer as a character string. the commas * are printed merely for clarity. * nx = 40 n = 1 nset = 1 num = array(1000) num<1> = 1 fill = array('0:3') fill<0> = '000' fill<1> = '00' fill<2> = '0' * output = ' Table of factorials for 1 through ' nx output = * * compute the next value from the previous one * l1 i = 1 l2 num = num * n :f(err) i = lt(i,nset) i + 1 :s(l2) i = 1 l3 lt(num,1000) :s(l4) numx = num / 1000 :f(err) num = num + numx :f(err) num = num - 1000 * numx :f(err) l4 i = lt(i,nset) i + 1 :s(l3) * * form a string representing the factorial * l5 nset = differ(num) nset + 1 number = num :f(err) i = gt(nset,1) nset - 1 :f(l7) l6 number = number ',' fill)> num i = gt(i,1) i - 1 :s(l6) * * output a line of the table * l7 output = n '! = ' number n = lt(n,nx) n + 1 :s(l1)f(end) * * error termination * err output = n '! cannot be computed because of table overflow' output = ' increase the size of array "num".' end