A program is a set of commands or instructions (a bit like a recipe) telling the calculator what to do. So a program is useful if you want to do several repetitive calculations. The simplest example isn't really a program at all: the result of the previous calculation is always stored in the memory called 'Ans'. This can be used in an iterative calculation where the answer at each step depends on the previous step.
Before reading on, note that to use commands like 'Ans' you should press the button or menu item with 'Ans' written on it, as opposed to typing the individual letters which would mean 'A' multiplied by 'N' multiplied by 'S'. If on your calculator 'Ans' appears above a button rather than on it, you may need to press 'shift' first.
Example : Suppose a bank account with an initial balance of L600 is given 2% interest a month but is also charged by L10. Now assuming there are no deposits or withdrawals then what will the balance be each month for the next year? Solution : Type the number 600 and press the 'EXE' button. Now type 1.02Ans-10 and keep pressing 'EXE'. Each press will display the next monthly balance.
The above example was made up of one instruction repeated over and over. Usually however, programs involve several different instructions to be carried out. In order to avoid having to retype the program, the calculator has a program mode for storing programs in memory to be recalled when needed. On most models this is mode2 so press the mode button followed by 2 (on icon models press menu and an icon tells you which mode). You are presented with a number of memory areas. Choose an area and move the arrow keys until that area is highlighted. Press 'EXE' and you are now in that area. Anything you type will be saved.
Example : Enter the program below into one of the memory areas, taking into account the following:
"A"?->A "B"?->B "C"?->C B^2-4AC->D (-B + sqrt D)2A_ (-B - sqrt D)2ATo start or run the program, press 'MODE' and the number '1' to get back to usual calculation mode which is called comp mode. Then type the 'Prog' command followed by the number of the area you in which you stored the program. e.g. Prog 3. The above example, when run, will ask you for the coefficients of a quadratic equation AX^2+BX+C=0 and display the real solutions if it has any (on models with complex capability it will display the appropriate result). Try entering 1, 3, 2 for the values if A, B, and C. This illustrates a program taking input from the user and producing output depending on the input. It also shows that values or results of expressions can be stored in variables A,B,C etc. (called value memories in the manual). When a program asks for input then type a number and press 'EXE'. When a program pauses to display something then press 'EXE' to continue.
There are also commands to skip part of the program.
Example : 10->A Lbl 1 A_ Dsz A Goto 1Here the 'Goto' command means jump to the corresponding 'Lbl'. You can use Labels 0-9 and A-Z. (on early models only Lbl 0-9) The 'Dsz' command means decrement the following variable value by 1, unless it is already zero in which case skip the next statement. So this program displays the values 10,9,8,7 etc. but when A reaches zero it skips the Goto command and the program ends. The last number is displayed twice because when a program ends it always displays the value in Ans memory.
As well as single letter variables A, B, C etc. you can use arrays. Consider the following example.
Example : 8->N Lbl 1 ?->A[N] Dsz N Goto 1 1->N Lbl 2 A[N]_ Isz N N<=8=>Goto 2This asks the user for 8 numbers and then displays the results in the reverse order from which they are typed. By using the array A[N] allowing N to vary with a Lbl-Goto loop we get A[1], A[2], ... which makes for a shorter program than writing : ?->A : ?->B : ?-C etc. if N is large enough. There is no extra memory for these arrays though so what happens is that A[0] stores values in A, A[1]=B, A[2]=C, A[3]=D etc. B[0]=B, B[1]=C, B[2]=D, ..., P[1]=Q, P[2]=R, P[3]=S etc. If you want to use an array without overwriting other letters then use Z[0], Z[1], etc. but first the memory must be expanded with the 'Defm' command. : Defm 10 : allows Z[1]~Z[10] to be used. Using the Defm command uses up 8 bytes of memory for every extra value memory you allocate This example also shows how the implication => symbol works. It means if something true then do something else.
If you look at some of the programs, you will see that it uses two program areas. During the main program it calls the second one with the 'Prog' command. When the second one ends it returns to the point in the main program. This is called using a subroutine. It is useful if a program does the same thing several times. Instead of repeating the same code, just put it in a subroutine.