Matthew Brown wrote:i < n would work. But if you set the condition to i <= n, what's going to happen when i = n?
(You don't even have to go as far as n/2 to work out if it's prime - think about it)
when i=n the condition will be true and as usual it enters in to the for loop and it will execute res=n%i and so on..
what ever the condition either i<=n and i<=n/2 it will be true and will go in to for loop and whats the difference is there output.
i am raising these doubts according to my knowledge.