answersLogoWhite

0

Just write a loop that goes through "candidates" (for example, numbers from 2 to 100). To check whether each number is a Prime number, write a second loop that checks whether it is divisible by all numbers from 2 up to the number itself. If the first factor you thus find is the number itself, then it is a prime number. For example, in Java:


...

for (i=2; i<=100; i++)

Â? for (j=2; j<= i; i%j<>0);

Â? if (i==j) System.out.println(i);

...


Note that the second "for" loop uses an empty instruction, so it will just increment the variable "j" until it finds a factor.


Also note that the program is "optimized" for simplicity; it is not optimized for speed.


User Avatar

Wiki User

15y ago

What else can I help you with?