Factorization of factorization in JS

Source: Internet
Author: User

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>Title</title>
<script type= "Text/javascript" >
var num = prompt ("Please enter a positive integer for the factor you want to decompose:", "1")
if (IsNaN (num) = = true) {
num = prompt ("Please enter a positive integer for the factor you want to decompose:", "1")
}
if (num <= 0) {
num = prompt ("Please enter a positive integer for the factor you want to decompose:", "1")
}
num = parseint (num);
var nump = num;
var arrfactor = [];
var L = 0;
var arrprem = [];
var k = 0;
for (var i = 2; i < num; i + +) {
var isprem = true;
for (var j = 2; J < I; J + +) {
if (i% j = 0) {
Isprem = false;
}
}
if (Isprem = = True) {
Arrprem[k] = i;
K + +;
}
}
for (var i = 0; i < arrprem.length;) {
if (num% arrprem[i] = = 0) {
num = Num/arrprem[i];
ARRFACTOR[L] = Arrprem[i];
L + +;
i = 0;
}else{
i + +;
}
}
document.write ("positive integer" + nump + "=");
if (Arrfactor.length = = 0) {
document.write ("You enter the number of ...")
}else{
for (var i = 0; i < arrfactor.length-1; i + +) {
document.write (Arrfactor[i] + "x");
}
document.write (Arrfactor[arrfactor.length-1]);
}


</script>
<body>

</body>

Factorization of factorization in JS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.