Follow the logic:
- You enter a number,
a
.
- The program creates
b
as 1
.
- The program immediately adds
1
to b
, so that b
is now 2
.
- The program sets
k
to a/b
. This means that k
is now half of a
.
- The program sets
p
to k
without the .5 that may or may not be there.
- If
p
(half of a
rounded down) is equal to k
(half of a
not rounded down), that is, if a
is divisible by b
, it goes to 100 and says it is not a prime number
.
- Otherwise, if
b
(which is 2
) is less than a
the program goes to line 30 and adds another 1
to b
and repeats the process, but now b
is 3
.
- Otherwise, if
b
(which is 2
) is equal to a
or greater than it, it prints that this is a prime number.
Let's say that the number you enter is 2. Two is, in fact, a prime number. Follow the logic above, however, and you will see that the program will tell us that it is not a prime number, because at step 6, two divided by two is one, and one truncated is still one. The same should be true for any number except 1, because all numbers are divisible by themselves.
My guess is that in your testing, you never tested 1; the program should say that 1 is a prime number (this is because even though 1 is divisible by itself, you start at b=2).
(Note also that this is also technically wrong: one is not a prime number.)