2. Doing arithmetic Rexx has a wide range of arithmetic operators, which can deal with very high precision numbers. Here is an example of a program which does arithmetic. I Make a file called "arith.rexx" containing the following. O Make a file called "arith.cmd" containing the following. /* This program inputs a number and does some calculations on it */ pull a b=a*a c=1/a d=3+a e=2**(a-1) say 'Results are:' a b c d e I Run it with "rexx arith" and type in a positive integer. O Run it by typing "arith" and type in a positive integer. Here is a sample run: I rexx arith O arith 5 Results are: 5 25 0.2 8 16 The results you see are the original number (5), its square (25), its reciprocal (0.2), the number plus three (8) and two to the power of one less than the number (16). This example illustrates several things: * variables: in this example a, b, c, d and e are variables. You can assign a value to a variable by typing its name, "=", and a value, and you can use its value in an expression simply by typing its name. * input: by typing "pull a" you tell the interpreter to ask the user for input and to store it in the variable a. * arithmetic: the usual symbols (+ - * /) as well as ** (to-power) were used to perform calculations. Parentheses (or "brackets") were used to group together an expression, as they are in mathematics. * string expressions: the last line of the program displays the results by saying the string expression 'Results are:' a b c d e This has six components: the string constant 'Results are:' and the five variables. These components are attached together with spaces into one string expression, which the "say" command then displays on the terminal. A string constant is any sequence of characters which starts and ends with a quotation mark - that is, either " or ' (it makes no difference which you use, as long as they are both the same). If you supply the number 6 as input to the program, you should notice that the number 1/6 is given to nine significant figures. You can easily change this. Edit the program and insert before the second line: numeric digits 25 If you run this new program you should see that 25 significant figures are produced. In this way you can calculate numbers to whatever accuracy you require, within the limits of the machine. At this point it seems worth a mention that you can put more than one instruction on a line in a Rexx program. You simply place a semicolon between the instructions, like this: /* This program inputs a number and does some calculations on it */ pull a; b=a*a; c=1/a; d=3+a; e=2**(a-1); say 'Results are:' a b c d e Needless to say, that example went a bit over the top...