For the code, see:
OPTION BASE 1DIM buff(16000) AS LONGPRINT "calc n!"INPUT "n="; nn%rad& = 10000arrLen% = 1buff(1) = 1FOR i% = 1 TO nn% STEP 1 cc& = 0 FOR j% = 1 TO arrLen% STEP 1 tt& = buff(j%) * i% + cc& buff(j%) = tt& MOD rad& cc& = tt& \ rad& NEXT IF (cc& > 0) THEN arrLen% = arrLen% + 1 buff(arrLen%) = cc& END IFNEXTPRINT "n!="; LTRIM$(RTRIM$(STR$(buff(arrLen%))));FOR i% = arrLen% - 1 TO 1 STEP -1 s$ = LTRIM$(RTRIM$(STR$(buff(i%)))) len1% = LEN(s$) IF (len1% < 4) THEN PRINT STRING$(4 - len1%, "0"); END IF PRINT s$;NEXT
Note:
1. The program is compiled in QBASIC.
QBASIC can be downloaded from the http://xiazai.zol.com.cn/detail/14/132311.shtml
QBASIC learning, refer to the http://www.zz5z.net/qb/index.htm
2. QBASIC is a 16-bit dos program. The array size cannot exceed 64 KB. Therefore, the array buff (16000) is defined ). 16000 × 4 <64 K
3. Describe the bas program so as not to forget its syntax for a long time.
3.1 Description of variable name suffix
%: Integer, 2 bytes, &: long integer, 4 bytes, $: string.
3.2 use () instead of brackets for Arrays
3.3 OPERATOR: mod remainder, "/" Division
3.4 input. The first string indicates the prompt information.
3.5 print output, ":" split indicates compact format output, "," delimiter of each field, loose format output
3.6 functions, string functions end with $,
String $, repeated strings
Ltrim $, rtirm $: Remove leading/trailing Spaces
STR $: convert a value to a string
4 Performance Comparison: Compared with the DOS batch processing and Linux bash, although it is an explanatory language, QBASIC runs much faster than DOS batch processing and Linux bash.