Lesson #9 Functions - Radio Shack TRS-80 Model 100 Basic Manual

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

Lesson #9 Functions
In this Lesson you will learn how to use certain functions to reduce the number of
program lines that would be required to carry out frequently encountered tasks.
Experiment #1 Calculating Square Root
This experiment will show you how to compute the square root of a number using the
built-in function capabilities of your Computer.
To obtain the square root of a number, simply type:
PRINT SQR(n)
(ENTER)
where
n
can be any positive number. For example to find the square root of 4, type:
PRINT SQR(4)
(ENTER)
which will print the correct result:
2
Now print the square root of 2 by entering
,
PRINT SQR(2)
and observe the correct result
1.414213562373
Finally,
try
to print the square root of the negative number
-4
by entering
PRINT SQR(-4)
and obtain the error message:
?FC Error
The error message indicates a "Function Call" error which occured because the
Computer cannot find the square root of negative numbers.
The square root function SQR(x) returns a numerical value for a specified numerical
"argument" x enclosed within the parentheses. The argument must be non-negative,
but can be a constant, variable or expression. For example, enter the following
A
=
3 : 6
=
4 : PRINT SQR(A*A
+
6*6)
to compute the length of the diagonal of a rectangle whose sides are of length 3 and 4.
The correct length is printed as
5
as seen in the illustration below:
111

Advertisement

Table of Contents
loading

Table of Contents