Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)

User Commands (d - f) dc(1)
Enter:
16 63 5 / + p [ Divide 63 by 5, add the result to 16 ]
The system responds as follows:
28.600
Enter:
16 63 5 + / p [ Add 63 and 5, divide the result by 16 ]
The system responds as follows:
0.235
You can type the comments (enclosed in brackets) into the command, but they are pro-
vided only for your information.
When you enter dc expressions directly from the keyboard, press the End-of-File key
sequence to end the dc session and return to the shell command line.
2. To load and run a dc program le, proceed as follows:
Enter:
dc prog.dc
5 lf x p [ 5 factorial ]s.
The system responds as follows:
120
Enter:
10 lf x p [ 10 factorial ]s.
The system responds as follows:
3628800
This command interprets the dc program saved in prog.dc then reads from thestandard
input le. The lf x evaluates the function stored in register f, which could be dened in
the program le prog.dc as:
[ f: compute the factorial of n ]s.
[ (n = the top of the stack) ]s.
[ If 1>n do b; If 1<n do r ]s.
[d1>bd1<r]sf
[ Return f(n) = 1 ]s.
[d-1+]sb
[ Return f(n)=n*f(n-1) ]s.
[d1-lfx*]sr
You can create dc program les with a text editor or with the -c (compile) ag of the bc
command. When you enter dc expressions directly from the keyboard, press the End-of-
File key sequence to end the dc session and return to the shell command line.
527188-003 Hewlett-Packard Company 37