I have been working with this code on my own for a whole day and still confused on why it doesn't work.. So what I'm trying to do here is determine whether a number the user is prime or not. But instead of determining that it just puts "Number is prime" on every number entered. Is there a rounding problem of the double in the for loop? Please reply asap.
n <= square_root_of_n; will always be false and your for loop will exit immediately. Since is_prime is initially true, the next code block that checks if(is_prime) will always be true.
I think you meant to put:
1 2 3 4
for(int i = 2; i <= square_root_of_n; i++)
{
...
}
The exit condition should be i <= square_root_of_n;