2

I have a program called FACTORS that prompts for an input value, and computes and displays a list of all the factors of that input number.

Now I want to write another program that calls FACTORS a couple of times and then loops through the lists of factors.

So I want to be able to do something like

prompt A
prgmFACTORS(A) -> L1

How can I re-write my FACTORS program to take a passed in parameter instead of prompting for it, and pass the list as output to the calling program instead of displaying it?

I'm using a TI-Nspire in TI-84 Plus mode.

PurpleVermont
  • 1,179
  • 4
  • 18
  • 46

1 Answers1

1

The most common pattern for simple parameters and return values in TI-Basic programming is the use of the Ans variable. The Ans variable automaticly stores the result of the last expression regardless of its data type.

Multiple parameters and return values can be used by using a list of values because Ans can hold both numeric and list values.

Using Ansis not mandatory to this approach. Any of the variables available through TI-Basic can be used in this manner but, in these cases, the value being returned or passed must be explicitly stored in the variable instead of the automatic storage provided by Ans.


In your sencario, this would look like this:

prompt A:A
prgmFACTORS
Ans→L₁

The code for the FACTORS program will likely need to be modified as well. Whatever list variable hold the value being returned should be placed on a line by it's self.

ankh-morpork
  • 1,732
  • 1
  • 19
  • 28