+1 1
-1 -1
6523 6523
-23.460 -23.46
1E20 1E+20
-12.3456E-7 -1.23456E-06
1.234567E-10 1.23457E-10
1000000000 1E+09
999999999 999999999
.1 .1
.01 .01
.000123 1.23 E-04
A number input from the keyboard or a numeric constant used in a BASIC program may have as
many digits as desired, up to the maximum length of a line (72 characters) or maximum numeric
value. However, only the first 10 digits are significant, and tenth digit is rounded up.
PRINT 1.23456789876543210
1.2345679
206 VARIABLES
ASSIGNING VARIABLES WITH AN INPUT STATEMENT
Following is an example of a program that reads a value from the keyboard and uses that value to
calculate and print a result:
10 INPUT R
20 PRINT 3.14159*R*R
RUN
?10
314.159
Here's what's happening: When BASIC encounters the input statement, it outputs a question mark
(?) on the display and then waits for you to type in a number. When you do (in the above example,
10 was typed), execution continues with the next statement in the program after the variable (R)
has been set (in this case to 10). In the above example, line 20 would now be executed. When the
formula after the PRINT statement is evaluated, the value 10 is substituted for the variable R each
time R appears in the formula. Therefore, the formula becomes 3.14159*10*10, or 314.159.
If we wanted so calculate the area of various circles, we could rerun the program for each successive
circle. But, there's an easier way to do it simply by adding another line to the program, as follows:
30 GOTO 10
RUN
?10
314.159
?3
28.27431
?4.7
69.3977231
?
By putting a "GOTO" statement on the end of our program, we have caused it to go back to line 10
after it prints each answer for the successive circles. This could have gone on indefinitely, but we
decided to stop after calculating the area for three circles. This was accomplished by typing a
carriage return to the input statement (thus a blank line).
VARIABLE NAMES
The letter "R" in the program above is a "variable." A variable name can be any alphabetic
character and may be followed by any alphanumeric character (letters A to Z, numbers 0 to 9).
Any alphanumeric characters after the first two are ignored.
Here are some examples of legal and illegal variable names:
Legal Illegal
A % (first character must be alphabetic)