The following code has a bug. Can you find it?
The code is supposed to check if a number is prime.
int isPrime(int num) {
int upperLimit = (int)(sqrt(num));
int i;
for (i = 2; i <= upperLimit; i++) {
if (i < num && num % i == 0) return 0;
}
return 1;
}
int isPrime(int num) {
int upperLimit = (int)(sqrt(num));
for (int i = 2; i <= upperLimit; i++) {
if (i < num && num % i == 0) return 0;
}
return 1;
}
public int isPrime(int num) {
int upperLimit = (int)(Math.sqrt(num));
for (int i = 2; i <= upperLimit; i++) {
if (i < num && num % i == 0) return 0;
}
return 1;
}
def isPrime(self, num):
upperLimit = int(num**0.5)
for i in xrange(2, upperLimit + 1):
if i < num and num % i == 0:
return 0
return 1
** Solutions coming up soon :)**