Commodore PET 2001 Series Introduction Manual page 14

Hide thumbs Also See for PET 2001 Series:
Table of Contents

Advertisement

packs the power of several programmable calculators put together,
it is as easy to use as a simple four-function calculator. Furthermore,
everything you type into it is instantly displayed on the screen, and
that makes it easier to keep track of what you are doing.
To perform arithmetic on your PET, simply tell it in BASIC to print
your answer. Note how much it looks like a direct question:
? 2 + 2
When you press the RETURN key. PET prints the result on the
screen.
PET arithmetic is not complex or mysterious. But, like human arith-
metic, it does have rules. One of the most important rules is
the order of operation:
I . exponentiation
2. multiplication and division
3. addition and subtraction
In direct mode, type:
?9*3+7*6-5*4/3*2 PET
will respond: 100.
666667
You (because you're the one in charge here) decide how to group the
expression so the result will be correct. You do this with parentheses.
Type:
?(9*8+7)*6-5*4/3*2
PET says:
460.666667
Type:
?(9*8+7*6-5)*(4/3*2)
PET says:
290.666667
14
t ( a b o v e R E T U R N k e y )
* /
+-
Type:
?((9*8+7*6-5*4)/3)*2
PET says:
62.6666667
Type:
?(9*8+7*6-5*(4/3)1*2
PET says:
214.666667
PET does all the work inside the parentheses first, before it does any-
thing outside of them. Once inside parentheses, PET does
multiplication and division, then addition and subtraction. After all
the work inside the parentheses is done, PET moves outside and does
everything"
there.
Let's look now at some of the arithmetic functions and find out how to
use them. First, type NEW, to delete the program we were using. Now,
type these program lines:
100 F O R I = 1 t o 1 0 120
PRINT I,I*I,SQR(I) 130
NEXT I
and RUN.
The result represents I (the count or index), I squared (the * means
multiply), and the square root of I. SQR(X ) is the Square Root func-
tion, and finds the square root of whatever number you put inside the
parentheses. Like all BASIC functions, SQR(X) requires an
any number you choose, enclosed in parentheses. Arithmetic expressions
can be used if you like instead of numbers, like SQR(5*20)
All the arithmetic functions are used in a similar fashion. Turn to the
BASIC keywords (Appendix II) and find the section on Arithmetic
functions. You can check out the way each one works by substituting it
for one of the functions in line 1 2Q of the program. The brief
description of the function, along with actually trying it yourself, will
show you how to use it.
www.commodore.ca
Free for personal use but you must have written permission to reproduce
argument
25

Advertisement

Table of Contents
loading

Table of Contents