|
-
Sep 8th, 2000, 06:13 AM
#1
Thread Starter
Hyperactive Member
Hi there,
I generate two random numbers and I'm looking for a way to find the lowest common denominator between them.
Say my numbers generated are 6 and 10. Well my code says 'if 6 Mod 10 =0, then lowest denominator is 6, or if 10 Mod 6 =0, then lowest denominator is 10....if neither of these is the case, then multiply 6 by 10 and that's the lowest denominator, i.e: 60. But we all know 30 is actually the lowest denominator.
This is what I use at present, but it's not good enough.
'2 command buttons
'two pictureboxes
Dim random1 As Integer
Dim random2 As Integer
Dim lowestdenom As Integer
Private Sub Command1_Click()
Randomize
random1 = Int(Rnd * 20) + 1
random2 = Int(Rnd * 20) + 1
Picture1.Cls
Picture1.Print random1 & " " & random2
End Sub
Private Sub Command2_Click()
If random1 Mod random2 = 0 Then
lowestdenom = random1
End If
If random2 Mod random1 = 0 Then
lowestdenom = random2
End If
If random1 Mod random2 <> 0 And random2 Mod random1 Then
lowestdenom = (random1 * random2)
End If
Picture2.Cls
Picture2.Print lowestdenom
End Sub
Any help would be appreciated!
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
|