Maxcompute factorial-Basic

Source: Internet
Author: User
Tags rtrim

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.