VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Calculates the prime factors of a number (e.g. 60 = 2 x 2 x 3 x 5)

by Sameet Natekar (6 Submissions)
Category: Math/Dates
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Wed 23rd June 2010
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Calculates the prime factors of a number (e.g. 60 = 2 x 2 x 3 x 5)

API Declarations


intNumber is the input number e.g. 60


Rate Calculates the prime factors of a number (e.g. 60 = 2 x 2 x 3 x 5)



                if (isNumeric(intNumber)= true) then
                    i=0
                    newn = intNumber
                    while (newn<>1)
                        j=2
                        flag = 1
                        while ((j<=newn) and (flag=1))
                            if (newn mod j = 0) then
                                intPrim = intPrim & j & ","
                                newn = newn/j
                                i=i+1
                                flag = 0
                            else
                                j=j+1
                            end if
                        wend
                    wend
                    if intPrim <> "" then intPrim = Left(intPrim,Len(intPrim)-1)
                    arrPrim = Split(intPrim,",")
                    for i=0 to ubound(arrPrim)
                        if i=0 then
                            strPrim = arrPrim(i)
                        else
                            strPrim = strPrim & " X " & arrPrim(i)
                        end if
                    next
                end if

Download this snippet    Add to My Saved Code

Calculates the prime factors of a number (e.g. 60 = 2 x 2 x 3 x 5) Comments

No comments have been posted about Calculates the prime factors of a number (e.g. 60 = 2 x 2 x 3 x 5). Why not be the first to post a comment about Calculates the prime factors of a number (e.g. 60 = 2 x 2 x 3 x 5).

Post your comment

Subject:
Message:
0/1000 characters