CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2011
    Posts
    5

    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...

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  3. #3
    Join Date
    Dec 2011
    Posts
    5

    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

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Find the semi perfect numbers

    Try two ListBoxes...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Nov 2002
    Posts
    278

    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

  7. #7
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  8. #8
    Join Date
    Nov 2002
    Posts
    278

    Re: Find the semi perfect numbers

    Quote Originally Posted by DataMiser View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured