Texas Instruments TI-92 Calculator User Manual


 
312 Chapter 17: Programming
17PROGRM.DOC TI-89/TI-92 Plus: Programming (English) Susan Gullord Revised: 02/23/01 1:14 PM Printed: 02/23/01 2:18 PM Page 312 of 40
This example uses
Dialog...EndDlog
to create dialog boxes for input
and output. It uses
Loop...EndLoop
to calculate the result.
:prog4()
:Prgm
:Dialog
: Title "Enter an integer"
: Request "Integer",n
:EndDlog
:expr(n)
!
n
:0
!
temp:0
!
i
:Loop
: temp+i
!
temp
: i+1
!
i
: If i>n
: Exit
:EndLoop
:Dialog
: Title "The answer is"
: Text string(temp)
:EndDlog
:EndPrgm
This example uses the
TI
-
89 / TI
-
92 Plus
built-in functions to calculate
the result without using a loop.
:prog5()
:Prgm
:Input "Enter an integer",n
:sum(seq(i,i,1,n))
!
temp
:Disp temp
:EndPrgm
Function Used in this example to:
seq
Generate the sequence of integers from
1
to
n
.
seq
(
expression
,
var
,
low
,
high
[,
step
])
sum
Sum the integers in the list generated by
seq
.
Example 4
Example 5
Note:
Because
Input
returns n as a number, you
do not need to use
expr
to
convert n.
expression used to generate the sequence
Converts string entered
with
Request
to an
expression.
variable that will be incremented
Defines a dialog box
for input.
initial and final values of
var
increment for
var
;
if omitted, uses 1.
Defines a dialog
box for output.
Calculates sum.
Displays output on
Program I/O screen.
Prompts for input on
Program I/O screen.
Loop calculation.