We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent acddf67 commit 49787e2Copy full SHA for 49787e2
Repetition Problems/For Loop/PrimeFactors.js
@@ -0,0 +1,20 @@
1
+/*
2
+ Write a program to compute Factors of a number N using prime factorization method.
3
+ Logic -> Traverse till i*i <= N instead of i <= N for efficiency.
4
+ O/P -> Print the prime factors of number N.
5
+*/
6
+
7
+const prompt = require("prompt-sync")();
8
+console.log();
9
+let n = parseInt(prompt(" Enter the number : "))
10
+console.log(" The Prime Factors are : ");
11
+for (i = 2; i * i <= n; i++) {
12
+ while (n % i == 0) {
13
+ console.log(" " + i);
14
+ n = n / i;
15
+ }
16
+}
17
+if (n != 1) {
18
+ console.log(" " + n);
19
20
0 commit comments