VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Prime factorizes a number

by RedSting71 (9 Submissions)
Category: Math/Dates
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Wed 23rd February 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Prime factorizes a number

Rate Prime factorizes a number



-------------------------------------------------------------------------------
Public function Math_PrimeFactorize(byval number as double) as string
b = 3
If Not Math_IsInteger(Val(number)) Then Exit Function
Line0:
    a = number
    GoTo Line2
Line1:
    true1$ = true1$ + "2,"
    a = a / 2
    If a = 1 Then GoTo Line9
Line2:
    If Math_IsInteger(a / 2) Then GoTo Line1: b = 3
Line3:
    c = Sqr(a) + 1
Line4:
    If b >= c Then GoTo Line8
    If Math_IsInteger(a / b) Then GoTo Line6
Line5:
    b = b + 2
    GoTo Line4
Line6:
    If a / b * b - a = 0 Then GoTo Line7: GoTo Line5
Line7:
    true1$ = true1$ + "," + Trim(str(b))
    a = a / b: GoTo Line3
Line8:
    true1$ = true1$ + "," + Trim(str(a))
Line9:
    d = Len(true1$)
    Math_PrimeFactorize = Trim(str(number)) + "{" & true1$ + "}"
end function
-----------------------------------------------------
public function math_isinteger(byval number as double) as boolean
n1 = Trim(str(number))
n = InStr(1, n1, ".")
If n = 0 Then Math_IsInteger = True
If n > 0 Then Math_IsInteger = False
end function

Download this snippet    Add to My Saved Code

Prime factorizes a number Comments

No comments have been posted about Prime factorizes a number. Why not be the first to post a comment about Prime factorizes a number.

Post your comment

Subject:
Message:
0/1000 characters