|
-
December 3rd, 2011, 12:17 AM
#1
Find the semi perfect numbers
Hi friends,
I have a question about finding the semi perfect numbers. Semi perfect number: The sum of three biggest divisors of any number apart from the number equals the that number.
For example:
6's divisors : 6, 3, 2, 1 >>> 3 + 2 + 1 = 6 This is semi perfect
30's divisors : 30, 15, 10, 6, 5, 3, 2, 1 >>> 15+10+6 = 31 This isn't semi perfect
36's divisors : 36, 18, 12, 9, 6, 4, 3, 2, 1 >>> 18+12+9 = 39 This isn't semi perfect
18's divisors: 18, 9, 6, 3, 2, 1 >>> 9 + 6 + 3 = 18 This is semi perfect.
I want there is a combobox. In combobox there will be 4 option " 1 2 3 4". When I click "1" it will print the semi perfect numbers in one stage on picturebox. When I click "2" it will print the semi perfect numbers in two stage
on picturebox.
I did lots of tries but it didn't work. At least If you give me the diagram, it will be perfect for me.
Thanks...
-
December 3rd, 2011, 12:20 AM
#2
Re: Find the semi perfect numbers
You should start by showing us what you tried. Be sure to use code tags to retain formatting so we can read it.
Always use [code][/code] tags when posting code.
-
December 3rd, 2011, 09:18 AM
#3
Re: Find the semi perfect numbers
Firstly, Thanks for reply. I couldn't make the diagram. I need to know how to do it. That's why I didn't do anything remarkable
-
December 3rd, 2011, 11:59 AM
#4
Re: Find the semi perfect numbers
I have no idea what you even mean by diagram here. If you tried several times then you have written some code. If you show us what you tried someone may help but you will not find many who will write it for you.
Always use [code][/code] tags when posting code.
-
December 3rd, 2011, 02:30 PM
#5
Re: Find the semi perfect numbers
-
December 9th, 2011, 12:51 PM
#6
Re: Find the semi perfect numbers
Does this help?
Code:
Private Sub FindPerfectNumbers()
Const SIX_DIVISORS As String = "6, 3, 2, 1"
Const THIRTY_DIVISORS As String = "30, 15, 10, 6, 5, 3, 2, 1"
Const THIRTY_SIX_DIVISORS As String = "36, 18, 12, 9, 6, 4, 3, 2, 1"
Const BARELY_LEGAL_DIVISORS As String = "18, 9, 6, 3, 2, 1"
Dim sSemi() As String
On Error GoTo FindPerfectNumbersErrHandler
sSemi = Split(SIX_DIVISORS, ", ")
If Int(sSemi(0)) = Int(sSemi(1)) + Int(sSemi(2)) + Int(sSemi(3)) Then
MsgBox sSemi(0) & ", this one is semi perfect"
Else
MsgBox sSemi(0) & ", this one is not semi perfect"
End If
Erase sSemi
sSemi = Split(THIRTY_DIVISORS, ", ")
If Int(sSemi(0)) = Int(sSemi(1)) + Int(sSemi(2)) + Int(sSemi(3)) Then
MsgBox sSemi(0) & ", this one is semi perfect"
Else
MsgBox sSemi(0) & ", this one is not semi perfect"
End If
Erase sSemi
sSemi = Split(THIRTY_SIX_DIVISORS, ", ")
If Int(sSemi(0)) = Int(sSemi(1)) + Int(sSemi(2)) + Int(sSemi(3)) Then
MsgBox sSemi(0) & ", this one is semi perfect"
Else
MsgBox sSemi(0) & ", this one is not semi perfect"
End If
Erase sSemi
sSemi = Split(BARELY_LEGAL_DIVISORS, ", ")
If Int(sSemi(0)) = Int(sSemi(1)) + Int(sSemi(2)) + Int(sSemi(3)) Then
MsgBox sSemi(0) & ", this one is semi perfect"
Else
MsgBox sSemi(0) & ", this one is not semi perfect"
End If
Erase sSemi
FindPerfectNumbersExitPoint:
On Error Resume Next
Erase sSemi
Exit Sub
FindPerfectNumbersErrHandler:
Select Case Err.Number
Case Else
MsgBox "Error occurred in FindPerfectNumbers" & vbCrLf & vbCrLf & Err.Description, vbOKOnly + vbExclamation
End Select
Resume FindPerfectNumbersExitPoint
End Sub
-
December 9th, 2011, 03:28 PM
#7
Re: Find the semi perfect numbers
I think you missed the mark there. My assumption is that the goal would be to allow the user to enter a number (any number) and then have the program determine the status. Basically all the code above does is shows us those which were in the example, all the factors above are hard coded and we already know the result for those numbers so not much point in coding anything there.
Also note that the code above would fail on anything other than 6 at the first test since the factors are hard coded for 6.
If you enter one of the supported numbers above it looks like it would tell you once that it is perfect and 3 times that it is not perfect.
Last edited by DataMiser; December 9th, 2011 at 03:33 PM.
Always use [code][/code] tags when posting code.
-
December 9th, 2011, 05:10 PM
#8
Re: Find the semi perfect numbers
 Originally Posted by DataMiser
I think you missed the mark there. My assumption is that the goal would be to allow the user to enter a number (any number) and then have the program determine the status. Basically all the code above does is shows us those which were in the example, all the factors above are hard coded and we already know the result for those numbers so not much point in coding anything there.
Also note that the code above would fail on anything other than 6 at the first test since the factors are hard coded for 6.
If you enter one of the supported numbers above it looks like it would tell you once that it is perfect and 3 times that it is not perfect.
Indeed, it was a bit of a guess on my part. Im just sort of bored today, just throwing that out there in case it might give MerkeZ a different perspective or spawn a new thought possibly. .
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
|