Radio Shack TRS-80 Model 100 Basic Manual page 120

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

Advertisement

Clear memory with the NEW command and enter the following program:
10 INPUT "DISTANCE, DEGREES"; D,A
20 PI
=
4 * ATN(l)
30 R
=
A * PI / 180
40 H
=
D * TAN(R)
50 PRINT "HEIGHT IS"; H
Execute the program and enter a distance of 50 and an angle of 45 degrees.
The display will appear as:
DISTANCE, DEGREES? 50, 45
HEIGHT IS 49.999999990085
Ok
Execute the program several times with different values for the distance and angle in
degrees.
Line
19
The INPUT statement allows the distance and angle in degrees to be entered
from the keyboard.
Line 29 The value of the constant PI is required to convert the angle in degrees to
radians. While the constant could have been written out in decimal form. this
assignment statement eliminates the need to look it up in a table or to
try
to remember
it.
It
also serves to illustrate another function which is available in BASIC, the
arctangent (ATN). You might like to confirm that this expression calculates the
constant correctly. Type:
PRINT 4*ATN(1)
~
to display the constant
3.1415928531932
Line 39 The angle is converted from degrees to radians in this assignment statement.
Line
49
The height is computed using the tangent function. The built-in function TAN
requires the argument to
be
in radians.
Line 59 The PRINT statement displays the height.
114

Advertisement

Table of Contents
loading

Table of Contents