A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 one year ago
can anybody write the algorithm to display all the prime numbers between 1 and 100. Try to formulate a model for picking out the prime numbers from this range and describe the input,processing and the output intended
anonymous
 one year ago
can anybody write the algorithm to display all the prime numbers between 1 and 100. Try to formulate a model for picking out the prime numbers from this range and describe the input,processing and the output intended

This Question is Closed

ganeshie8
 one year ago
Best ResponseYou've already chosen the best response.2Using sieve of eratosthenes, you just need to check the divisibility with `2, 3, 5, 7`. Here I provide two different programs in javascript which i hope you may easily convert to an algorithm :

ganeshie8
 one year ago
Best ResponseYou've already chosen the best response.2#Method 1 (sieve of eratosthenes) ``` for (i = 2; i < 100; i++) { if (i != 2 && i % 2 == 0) continue; if (i != 3 && i % 3 == 0) continue; if (i != 5 && i % 5 == 0) continue; if (i != 7 && i % 7 == 0) continue; console.log(i); } ``` https://jsfiddle.net/ej13c8t4/1/

ganeshie8
 one year ago
Best ResponseYou've already chosen the best response.2#Method 2(regular expressions, this is the most inefficient algorithm but also the most coolest) ``` for (i = 2; i < 100; i++) { if ("1".repeat(i).match(/^(11+?)\1+$/)) continue; console.log(i); } ``` https://jsfiddle.net/8bwepcbs/1/

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0ha, that's clever @ganeshie8
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.