VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



The code calculates the prime factors of a number. E.g. 1456 = 2 X 2 X 2 X 2 X 7 X 13.

by Sameet Natekar (6 Submissions)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 27th July 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

The code calculates the prime factors of a number. E.g. 1456 = 2 X 2 X 2 X 2 X 7 X 13.

Rate The code calculates the prime factors of a number. E.g. 1456 = 2 X 2 X 2 X 2 X 7 X 13.



<HEAD>
<SCRIPT LANGUAGE=JavaScript>
function CalcPrime()
{
var prim = new Array();
disp = "";
n = Math.abs(Math.floor(frmMain.txtNum.value));
i=0;
if ((!(isNaN(n))) && (frmMain.txtNum.value.length!=0))
{
newn = n;
while (newn!=1)
{
j=2;
flag = 1;
while ((j<=newn) && (flag==1))
{
if (newn%j==0)
{
prim[i] = j;
newn = newn/j;
i++;
flag = 0;
}
else
j++;
}
}
for (i=0; i<prim.length-1; i++)
disp = disp + prim[i] + " X ";
disp = disp + prim[i];
}
if (frmMain.txtNum.value<0) { disp = disp + " X -1"; }
frmMain.txtSoln.value = disp;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME=frmMain>
<B>Enter the number</B>: <INPUT TYPE=Text NAME=txtNum onKeyUp=CalcPrime()>
<BR>
<TABLE><TR><TD><TEXTAREA NAME=txtSoln></TEXTAREA></TD></TR></TABLE>
</FORM>
</BODY>
</HTML>

Download this snippet    Add to My Saved Code

The code calculates the prime factors of a number. E.g. 1456 = 2 X 2 X 2 X 2 X 7 X 13. Comments

No comments have been posted about The code calculates the prime factors of a number. E.g. 1456 = 2 X 2 X 2 X 2 X 7 X 13.. Why not be the first to post a comment about The code calculates the prime factors of a number. E.g. 1456 = 2 X 2 X 2 X 2 X 7 X 13..

Post your comment

Subject:
Message:
0/1000 characters