Section 12: Subroutines183
Keystrokes Display    
RCL 01
  31 RCL 01    
   
RCL 03
  32 RCL 03    
   
 ×  
  33 *    
   
  34 4 _    
   
 ×  
  35 *    
   
 –  
  36 –    
   
  
  37 SQRT    
   
g GTO · · 
  00 REG 38    
   
Run the QROOT program now to find the roots of the equation x2 + x – 6 = 0 (a = 1, b = 1, c = –6); of 3x2 + 2x –1 = 0 (a = 3, b = 2, c = –1):
Keystrokes Display    
PRGM 
0.0000    
  Takes the HP-41C out of PRGM mode.
XEQ 
     
   
ALPHA QROOT ALPHA 
a?    
   
R/S 
b?    
   
R/S 
c?    
   
CHS R/S 
3.0000    
  The first root.
 
2.0000    
  The second root.
XEQ 
     
   
ALPHA QROOT ALPHA 
a?    
   
R/S 
b?    
   
R/S 
c?    
   
CHS R/S 
1.0000    
  The first root.
 
0.3333    
  The second root.
g CLX 
0.0000    
   
If the quantity b2 – 4ac is a negative number, the calculator will display DATA ERROR to let you know that the program has attempted to find the square root of a negative number. The program will stop running.
Details of Subroutine Usage
Subroutines give superb versatility in programming. A subroutine can contain a loop, or it can be executed as part of a loop. Subroutines can even be complete programs with their own ALPHA labels; separate from the program that executes it.