#include <stdio.h>
main()
{
printf("Enter a number: ");
int n;
scanf("%d", &n);
if(n == 2)
printf("%d is prime", n);
else if(n % 2 == 0 || n < 2)
printf("%d is not prime", n);
else
{
int x;
for(x = 0; x < (int)sqrt((double)n); x++)
if(n % x == 0)
{
printf("%d is not prime", n);
return;
}
printf("%d is prime", n);
}
}
If n is 2, less than 2, or a multiple of 2, then the program runs fine. Otherwise, I get told that it encountered a problem. I'm kind of new to C, so I'm not exactly sure what's wrong. My background is in Java =/
Can anybody see anything that may be causing the problem?




This topic is locked










