A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 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

  • This Question is Closed
  1. ganeshie8
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 2

    Using 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 :

  2. ganeshie8
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 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/

  3. ganeshie8
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 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/

  4. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://ideone.com/JKA2ik

  5. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ha, that's clever @ganeshie8

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.