Hi,
Please always use code tags:
Do you Google this before you wrote the code? There are millions of others who have already done this. You could learn some ideas: Limit is sqrt not x/2; specifically test for
num == 1
; use for
==
for comparison, not
=
Also look at the wiki page for this, near the end there is Euler's algorithm.
0 is supposed to exit the program, but it says it's not a prime. A good reason not to use a
do
loop, the condition is at the end :+)
The algorithm you are using is a typical naive one, and very inefficient - only good for small limits like 5,000 say. The problem is if the number is prime, it tests
every multiple regardless of whether it is already a multiple of something else. If the number mod 2 is false then number mod 4, 6, 8 .... will be false too. The same story for all the other trial factors too.
It is much better to start off with a list of all the numbers, then cull out ones which are not prime, then search for a particular number in the remaining list. This is not as hard as it sounds.
Good Luck !!