


Section 12: Subroutines192




You can continue to execute the local label programs any number of times using
the local label keys without executing the main program each time. All you
do is press A ( Σ+ ), B
( 1/X ), or C ( ) in
USER mode. But when the calculator is positioned outside of the SPEED program,
pressing the local keys search only the current program. If they are not
found, the function printed on or above the key is executed.


Application Module Function Execution


When you execute programs that are contained in an application module, the prompt
in the program is changed from
XEQ name to
XROM name . This lets you know that
the program is in the application module, not in program memory.


Problems



1.

Look closely at the program for finding roots r1
and r2 of a quadratic equation (page
182). Can you see other instructions
that could be replaced by a subroutine? (Look at lines 3 through 17 and
lines 20 through 24.) Modify the program by using another subroutine and run it to
find the roots of
x^{2} + x – 6 = 0; of
3x^{2} + 2x –1 = 0.




(Answers: –3.0000, 2.0000; –1.0000, 0.3333.)




Did you save any more lines of program memory?



2.

The surface area of a sphere can be calculated according to the equation
A = 4 π r^{2}, where r is
the radius. The formula for finding the volume of a sphere is
V = (4 π r^{3}) ÷ 3.
This may also be expressed as V = (r × A) ÷ 3.




Create and load a program to calculate the area A of a sphere given its
radius r. Name the program SAREA and include an initialization routine
to prompt for the value of the radius. Then create and load a second program to
calculate the volume V of a sphere, using the equation
V = (r × A) ÷ 3. Name this second program VOLUME and include
an XEQ SAREA to use SAREA as a subroutine to calculate
area.




Run the two programs to find the area and volume of the planet Earth, a sphere
with a radius of about 3963 miles and of the Earth’s moon, a sphere with a
radius of about 1080 miles.





(Answers:

Earth area = 197,359,487.5 square miles,


Earth volume = 2.6071188 × 10^{11} cubic miles;


Moon area = 14,657,414.69 square miles,


Moons volume = 5,276,699,290 cubic miles.)





