(新手求助)这个检查素数的程序哪里有问题呢?
谁能帮我看看这个检查一个数是否是素数的程序哪里有问题,谢谢! #include <stdbool.h>
#include <stdio.h>
bool is_prime(int n)
{
int divisor;
if (n <= 1)
return false;
for (divisor = 2; divisor * divisor <= n; divisor++)
if (n % divisor == 0)
return false;
return true;
}
int main(void)
{
int n;
printf("Enter a number: ");
scanf("%d", &n);
if (is_prime(n));
printf("Prime\n");
else
printf("Not prime\n");
return 0;
}
注:运行以后出现以下错误:
ERROR: Can't have an 'else' here
ERROR: syntax error before or at line 20 in file 'prime.c'
==>: else
BUG: else<== ??? bug may be here
ERROR: cannot execute command 'prime.c'
>Exit code: -1