Commodore — Commodore Business Machines PET 2001 (EN)

I String Functions (Continued) Arithmetic Operators call to RND. If A = 0, the same positive sequence of random numbers is generated each time RND is called. If A is greater than 0, a new sequence is produced for each call to RND. 10 A=1:8=2:C=3 Allows multiple statements on a line. 10 PRINT A;B Allows same line printing. Elements are separated by a space. 20 PRINT A$;B$ Allows same line printing. String elements SGN 10 C-SGN(A) Returns -1 if argument is negative, returns 0 if argument is zero, and returns +1 if argument is positive. are concatenated. 10 PRINT A,B Allows same line printing.

Elements are separated and printed in pre-TABbed print positions (columns 11,21,31, etc.) SIN 10 C=SIN(A) Returns sine of argument. A must be expressed in radians. LOAD "NAME,",D Separates elements in LOAD, SAVE, SQR 10 C=SQR(A) Returns square root of argument. OPEN, and VERIFY. ? 10 ?A Abbreviation for PRINT. Stores as one TAN 10 C TAN(A) Returns tangent of argument. A must be expressed in radians. 44 character; lists as word PRINT. Do not use for PRINT #. 45 FUNCTION EXAMPLE PURPOSE MID$ 10 ?MID$(X$,A,B) Returns B characters from string, starting with the Ath character.

RIGHTS 10 ?RIGHT$(X$,A) Returns rightmost A characters from string, S 1 R$ 10 A$=STRS(A) Returns string representation of number. VAL 10 A-VAL(A$) Returns numeric representation of string. 20 A=VAL("A") If string not numeric, returns "0". ASC, LEN and VAL functions return numerical results. They may be used as part of an expression. Assignment statements are used here for examples only; other statement types may be used. Arithmetic Functions FUNCTION EXAMPLE PURPOSE ABS 10 C=ABS(A) Returns magnitude of argument without regard to sign. ATN 10 C=ATN(A) Returns arctangent of argument. C will be expressed in radians. COS 10 C=COS(A) Returns cosine of argument. A must be expressed in radians.

DEF FN 10 DEF FNA(B)-C*D Allows user to define a function. Function label A must be a single letter; argument B a dummy. EXP 10 C-EXP(A) Returns constant 'e' raised to power of the argument. In this example, eA. INT 10 C=INT(A) Returns largest integer less than or equal to argument. LOG 10 C=LOG(A) Returns natural logarithm of argument. Argument must be greater than or equal to zero. RND 10 C-RND(A) Generates a random number between zero and one. If A is less than 0, the same nega SYMBOL EXAMPLE PURPOSE 10 A=B Assigns a value to a variable. 20 LET A=B Let is optional. | 30 PRINT A|2 Exponentiation; in example, A2.

Division / 35 C=A/8 40 C=A*8 Multiplication 50 C=A+B Addition 60 C=A-8 Subtraction 10 IF A=B THEN PRINT C A 'equals' B. 10 IF A B THEN C$=D$+E$ A 'is greater than' B. 10 IF A