Post Reply 
(9g) Sample programs
09-24-2022, 11:27 PM (This post was last modified: 09-24-2022 11:29 PM by Eddie W. Shore.)
Post: #1
(9g) Sample programs
Programs for the HP with a unique language, the hp 9g:

hp 9g Program: Integer Division

This program gives the quotient and remainder of N ÷ D. The program here assumes you enter positive integers, and some code can be entered for checking inputs.

Code:
INPUT N
INPUT D
Q=INT(N/D)
R=N-Q*D
PRINT Q," R",R
END

Examples:

N = 4379, D = 8; Result: 547 R3

N = 5884, D = 29; Result: 202 R26


Note: The PRINT command converts variable values to strings automatically, without the need for a string or STR$ command.

hp 9g Program: Arithmetic-Geometric Mean

This program determines the AGM given two numbers A and G.

Code:
INPUT A
INPUT B
PRINT "ACC. 10^-8"
Lbl 0:
X=.5(A+G)
Y=√(AG)
If (ABS(X-Y)<10^(-8))
Then {Goto 1}
A=X
G=Y
Goto 0
Lbl 1:
Print "ANS= ", X

Examples:

A = 1.3, G = 1.5, Result: ANS ≈ 1.39821143

A = 20, G = 45, Result: ANS ≈ 31.23749374


Notes:

10^ is from [ 2nd ] (10^x) the antilog function.

The label command must have the colon character after the label number, or a syntax error occurs.

If you run a program from the Main mode by the [ PROG ] key, you will be transferred to Program mode when the program finishes.

hp 9G Program: The Maximum Value of A through X


Y = maximum value
Z = counter variable

Code:
PRINT "MAX(A:X)"; ◢
FOR(Z=2;Z<23;Z++){
IF(A[Z]>Y)
THEN{Y=A[Z]}};
PRINT "MAX=",Y;
END

Example:

Clear all variable in the MAIN mode by CL-VAR
Set up variables:

A = 12, D = 24, E = 37, G = 40, S = 19, T = 16, U = 7
Result: MAX= 40

Notes:

++ is from the Instruction menu, it is a smaller-jointed double plus.

When the program encounters a run/stop instruction (◢), the last message is displayed. Continue execution by pressing the equals key [ = ].

hp 9g Program: Plotting y = A * sin(B * x + C) + D

The programming mode does not offer a lot of support when it comes to graphs. For instance, the last message prints over the graph. Furthermore, the angle mode (preferably Radians) and clearing the screen must be done in the Main mode before running the program. Neither the angle mode or variable/screen clearing can be programmed.

Code:
PRINT "SINE"
SLEEP(.5)
INPUT A,B,C,D
RANGE(-2π,2π,π/4,-A,A,1)
Graph Y=A*sin(BX+C)+D
PRINT "PRESS G<>T"
END

Although it wasn't used in the programs above, the FOR command is more like the C format, reminding me of the equation editor for the Plus42 app.

FOR(start condition; continue condition; next expression) {loop commands separated by a semicolon}
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(9g) Sample programs - Eddie W. Shore - 09-24-2022 11:27 PM
RE: (9g) Sample programs - bbergman - 09-25-2022, 03:41 PM
RE: (9g) Sample programs - rprosperi - 09-25-2022, 04:16 PM
RE: (9g) Sample programs - bbergman - 09-29-2022, 09:34 PM



User(s) browsing this thread: 1 Guest(s)