I am trying to find if 5915587277 is prime or not. This number is actually prime and I am expecting this from my program. When I run this program it says that it is not prime and its divisor is 199.
#include<stdio.h>
int main()
{
long n = 0;
long i = 0;
printf("Enter Number: ");
scanf("%ld", &n);
long m = n/2;
if(n%2 == 0)
{
printf("Not Prime");
return 0;
}
for( i = 3; i <= m; i++)
{
if(n%i == 0)
{
printf("Not Prime: %d\n", i);
return 0;
}
}
printf("Prime");
return 0;
}
I am not sure why this code is printing this number as NOT prime when it is.
You are exceeding the max value for a long. See Data type limits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With