Skip to content

Commit acddf67

Browse files
committed
[Shreyash]: Added code to check entered number is prime or not
1 parent 4b3a0ed commit acddf67

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Write program that takes input and determines if the number is a prime.
3+
*/
4+
5+
const prompt = require("prompt-sync")();
6+
console.log();
7+
let num = parseInt(prompt(" Enter the number : "))
8+
let count = 0;
9+
for (let i = 2; i <= num / 2; i++) {
10+
if (num % i == 0) {
11+
count += 1;
12+
break;
13+
}
14+
}
15+
if (count == 0 && num > 1) {
16+
console.log(" " + num + " is a Prime Number \n");
17+
}
18+
else {
19+
console.log(" " + num + " is not a Prime number \n");
20+
}

0 commit comments

Comments
 (0)