tôi tuân thành công mã này:Floating điểm ngoại lệ
#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);
}
}
}
Nhưng khi tôi chạy mã của tôi, tôi nhận được lỗi sau:
Floating point exception
không lỗi này có nghĩa là gì và làm thế nào tôi có thể sửa chữa nó?
Bạn cần thụt lề tất cả mã của mình để mã không được định dạng quá kỳ lạ. – hb2pencil
http://stackoverflow.com/questions/4122172/c-programming-floating-point-exception – TGar