First, provide the Code:
program fac;var i,j,n,len: integer; rad,c,r: longint; buff: array[1..16000] of integer; num: string[5];begin writeln('calculate n!'); write('n=?'); read(n); rad:=10000; len:=1; buff[1]:=1; for i:=1 to n do begin c:=0; for j:= 1 to len do begin r := buff[j] * i +c; buff[j] := r mod rad; c := r div rad; end; if c>0 then begin len:=len+1; buff[len]:=c; end; end; write('n!=',buff[len]); for i:=len-1 downto 1 do begin str(buff[i],num); if length(num)<4 then write(copy('0000',1,4-length(num))); write(buff[i]); end;END.
Note:
Development Environment: Free Pascal 2.4 (a DOS program, similar to Turbo Pascal)
Download Page: http://down.tech.sina.com.cn/page/46658.html
Free Pascal settings:
1. the DOS window code page is set to 437 (USA). Otherwise, garbled characters will occur.
2. Options-> compiler mode is set to Turbo Pascal compatible
Learning materials:
Pascal language training courses, download page http://www.05sun.com/downinfo/5433.html
Download, install free Pascal. It takes about two hours to learn, compile, and debug the program.
Problems:
1. Data overflow caused by the definition of variable R as integer
2. If the for keyword is deduplicated and changed to downto, everything is normal.