Hello everyone. Is there any way to easily calculate all possible fractions of a number using ti nspire CAS?
For example, I enter number 100 and receive output 1, 2, 4, 5, 10, 20, 25, 50, 100. Thanks!
Here's a slightly more optimized version:
Input "NUMBER?", A
{1→L₁
For(B,2,A/2
if not(fPart(A/B
B→L₁(1+dim(L₁
End
L₁
Hope this helps ;) Oh, keep in mind, this does not return the last factor; that is, the number itself. If you use your example, when you set A to 100, L1 becomes {1, 2, 4, 5, 10, 20, 25, 50}. Just so you know
its easy to fix N not being appended to the list.
Input "NUMBER?", A
{1→L₁
For(B,2,A/2
if not(fPart(A/B
B→L₁(1+dim(L₁
End
A→L₁(1+dim(L₁
L₁
Edit: would seq( be able to be used at all? it seems like it could be, but I'm not sure it would output what we want it to
Yeah it's pretty simple actually. Here's the code for it:
Input "Number?",A
int(A/2)->B
1->dim(L1)
For(C,1,B
If int(A/C)=A/C
Then
C->L1(dim(L1))
dim(L1)+1->dim(L1)
End
End
dim(L1)-1->dim(L1)
For(A,1,dim(L1
Disp L1(A)
End
L1
And yeah hope that helps, it'll find all the factors of any one number. Funny thing is that when I first went to make this program like a few minutes ago I apparently had already made a similar factoring program and had just left it in archive and forgot about it. It doesn't find the factors of one number but instead finds all the common factors of 2 numbers. Let me know if you want the code for that too. So yea, pretty cool stuff.
-HG
I cannot remember off the top of my head, but isn't there a factor() function built in?
Z80 Assembly>English>TI-BASIC>Python>French>C>0
Yes, it is, but it factors completely for example factor(100) you will get 2^2*5^2
Oh, okay. I must have remembered the factor() function from my TI-89 which I believe just made a list.
I can't remember if it's a built in library, but on mine I have a numtheory library with a function called divisors().
Goto Catalog (book symbol)
Press 6
Click on numtheory
scroll through the library functions
Alternatively, type numtheory\divisors(100).
Z80 Assembly>English>TI-BASIC>Python>French>C>0