Skip to content

Commit 7290791

Browse files
committed
[Shreyash]: Added code to print prime numbers from entered range
1 parent b8946d4 commit 7290791

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Write program that takes range as input and print prime numbers from that range
3+
*/
4+
5+
const prompt = require("prompt-sync")();
6+
console.log();
7+
let startNum = parseInt(prompt(" Enter the start number : "))
8+
let endNum = parseInt(prompt(" Enter the end number : "))
9+
10+
console.log(" Prime Numbers from given range are :");
11+
12+
for (var num = startNum; num <= endNum; num++) {
13+
if (num < 2) {
14+
continue;
15+
}
16+
var count = 0;
17+
for (let i = 2; i <= num / 2; i++) {
18+
if (num % i == 0) {
19+
count += 1;
20+
break;
21+
}
22+
}
23+
if (count == 0) {
24+
console.log(" " + num);
25+
}
26+
}
27+
console.log();

0 commit comments

Comments
 (0)