|
-
Apr 7th, 2001, 11:56 PM
#1
Thread Starter
Conquistador
Pretty simple i think, but how do I do it?
-
Apr 9th, 2001, 03:03 AM
#2
Addicted Member
check this..
Code:
Private Function IsFactor(Num, ofNum) As Boolean
'Checks If Num is A factor of ofNum
If Not Num = 0 Then
IsFactor = ofNum Mod Num
IsFactor = Not IsFactor
End If
End Function
Private Sub Command1_Click()
For i = -10 To 10
If IsFactor(i, 56) Then
List1.AddItem i
End If
Next
End Sub
BTW an iteration loop is no means an effiecient way to do this.
still it's logical for smaller ranges of numbers.
-
Apr 9th, 2001, 05:54 AM
#3
Thread Starter
Conquistador
Oh, OK...
I am working on some other code for factors and trinomials, so I will hopefully post that here
-
Apr 9th, 2001, 11:23 PM
#4
Frenzied Member
An approach.
I assume that you are talking about finding all prime factors of a given number. For example: 29, 17, 3, & 3 are the factors of 4437.
An approach would be to start by using an array of known primes: 2, 3, 5, 7, 11, 13, 17 . . . .
Find all the primes you can via the array. If there are more primes to be found, try every odd number after the last prime in the array.
For a VB program, you could have the user put a number into a Text Box, which you would immediatley put into a List Box. The general approach would be to work with the number put into the List Box, replacing it with two factors. For the above example, the List Box would contain the following after each cycle of the program.- 4437
- 3, 1479
- 3, 3, 439
- 3, 3, 17, 29
If you find no primes, the original number is the sole contents of the List Box.
Note the following.- You you never need try a factor greater than the square root of the number you are working with. When you get past the square root of the number, you are finished. This is how you know when to stop trying for more factors.
- Once you tried a number as a factor, you need not try that factor nor any smaller factor. This provides a rule for avoiding extra work.
I used the above general idea to write a factoring program for my HP48GX calculator. Instead of the List Box, I used the LIFO Stack provided by the calculator.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Apr 11th, 2001, 02:30 AM
#5
Thread Starter
Conquistador
mmmmkay, thanks, still a bit hazy about the idea, anybody else written a program for this?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|