Print First 20 Prime Numbers In Javascript | letsbug
Many time we are working on some of our project or solving some challenges we are required to check if the number is prime number or print the prime number. So therefor in this article we are print prime number from 1 to 20.
Printing First 20 Prime Numbers
code:
// javascript program to print prime number from 1 to 20function prime() {for (let i = 2; i <= 20; i++) {let prime = true;for (let j = 2; j < i; j++) {if (i % j == 0) {prime = false;break;}}if (prime) {console.log(i);}}}prime();
output:
2 3 5 7 11 13 17 19
This is a very nice post and it's helping us a lot. Hope you'll also visit our website to know about What is Authorization
ReplyDeleteCybersecurity Awareness | Are You Secure? – ProtectBD
secure.protectbd.com