Number which is sum of its factors like
factor of 6 is 1*2*3.
so 1+2+3=6
sum of factors is =number itself
hence 6 is perfect number .after that 28 is perfect number.
perfect number from 1 to 1000
is 6, 28, 496
Public Sub perfect()
Dim takeval As Integer = txtVal.Text
Dim valstore As Integer = 1
Dim flag As Integer = 0
Dim val2 As Integer
Dim Sum As Integer = 0
For val2 = 2 To (takeval - 1)
valstore = 1
Sum = 0
While valstore < val2
If (val2 Mod valstore = 0) Then
Sum = Sum + valstore
End If
valstore += 1
End While
If Sum = val2 Then
Response.Write(Sum & "is perfect number")
End If
Next
End Sub
factor of 6 is 1*2*3.
so 1+2+3=6
sum of factors is =number itself
hence 6 is perfect number .after that 28 is perfect number.
perfect number from 1 to 1000
is 6, 28, 496
Public Sub perfect()
Dim takeval As Integer = txtVal.Text
Dim valstore As Integer = 1
Dim flag As Integer = 0
Dim val2 As Integer
Dim Sum As Integer = 0
For val2 = 2 To (takeval - 1)
valstore = 1
Sum = 0
While valstore < val2
If (val2 Mod valstore = 0) Then
Sum = Sum + valstore
End If
valstore += 1
End While
If Sum = val2 Then
Response.Write(Sum & "is perfect number")
End If
Next
End Sub
hi, how to print all factor numbers for the perfect number in vb?anyone can help me.TQ
ReplyDeleteSIMPLE check this code
ReplyDeleteWhile valstore < val2
If (val2 Mod valstore = 0) Then
Sum = Sum + valstore
Response.Write("Factors are are")
Response.Write("")
Response.Write(valstore) 'it will print perfect numbers factor'
End If
valstore += 1
End While
If Sum = val2 Then
Response.Write(Sum & "is perfect number")