Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,872 questions

51,796 answers

573 users

How to check whether number is perfect or not in VB.NET

2 Answers

0 votes
Module Module1

    Sub Main()

        ' perfect number is a positive integer that is equal to the sum of its positive divisors
        Dim num As Integer = 496, i As Integer = 1, sum As Integer = 0

        Do While (i < num)
            If (num Mod i = 0) Then
                sum = sum + i
            End If
            i = i + 1
        Loop
        If (sum = num) Then
            Console.WriteLine("{0} is a Perfect Number", num)
        Else
            Console.WriteLine("{0} is Not a Perfect Number", num)
        End If

    End Sub

End Module

'run:
' 
'496 is a Perfect Number

 



answered Feb 26, 2016 by avibootz
edited Feb 26, 2016 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim num As Integer = 496

        If (isPerfectNumber(num)) Then
            Console.WriteLine("{0} is a Perfect Number", num)
        Else
            Console.WriteLine("{0} is Not a Perfect Number", num)
        End If

    End Sub

    Function isPerfectNumber(n As Integer) As Boolean
        Dim i As Integer = 1, sum As Integer = 0

        Do While (i < n)
            If (n Mod i = 0) Then
                sum = sum + i
            End If
            i = i + 1
            Loop
        Return sum = n
    End Function

End Module

'run:
' 
'496 is a Perfect Number

 



answered Feb 26, 2016 by avibootz

Related questions

4 answers 617 views
1 answer 162 views
1 answer 102 views
1 answer 110 views
...