我成功地遵守這個代碼:浮點異常
#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