我成功地遵守这个代码:浮点异常
#include <stdio.h>
#include <math.h>
int q;
int main()
{
srand(time(NULL));
int n=3;
q=ceil(sqrt(n));
printf("%d\n %d\n", n,q);
if(n == 2)
printf("%d\n is prime", n);
else if(n % 2 == 0.0 || n < 2)
printf("%d\n is not prime", n);
else
{
int x;
for(x = 0; x < q; x++){
if(n % x == 0)
{
printf("%d\n is not prime", n);
return;
}
else
printf("%d\n is prime", n);
}
}
}
但是当我运行我的代码,我得到以下错误:
Floating point exception
这个错误是什么意思,我该如何解决?
您需要缩进所有代码,以避免格式错乱。 – hb2pencil 2010-09-01 06:22:34
http://stackoverflow.com/questions/4122172/c-programming-floating-point-exception – TGar 2017-01-20 12:29:44