You need to set isPrime
to 0
each time the user enters a number. Otherwise, it still holds the value from the previous number.
Move the variable declaration
int isPrime = 0;
inside the while
loop.
BTW, isn’t that variable name backwards? You set it to 1
(i.e. true
) when you discover that there’s a number that divides it equally. But that’s when the number is not prime.
solved program that tells if a number is prime