answersLogoWhite

0

The simplest thing is to use the Sieve of Eratosthenes: make an array using the positive integers as the index up to 100.

Starting with 2, store 2 in your list of primes, and and then delete the variable for each multiple of 2 (4, 6, 8, etc.) Then find the smallest index that still exists (3); add 3 to your list of primes, and delete the variable for each multiple of 3 (6, 9, 12, etc.). Then find the next smallest index that still exists (5) and repeat the process over and over. When you reach 100, you're done. (There are many optimizations for this)

User Avatar

Wiki User

10y ago

Still curious? Ask our experts.

Chat with our AI personalities

ReneRene
Change my mind. I dare you.
Chat with Rene
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
More answers

Here they are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97

User Avatar

Wiki User

8y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What is a way to print all prime numbers between 1 to 100?
Write your answer...
Submit
Still have questions?
magnify glass
imp