Note that N is unused and you are calling is_prime twice for no good reason...
Code:
Y = is_prime (num);
N = is_prime (num);
if (Y == 1)
{
printf("%d is a Prime Number\n", num);
}
else
{
printf("%d is NOT a Prime Number\n", num);
}
You could have also done this...
Code:
if (is_prime ( num ))
printf("%d is a prime number.\n\n", num);
else
printf("%d is not a prime number.\n\n",num);
or maybe this...
Code:
printf ("%d is ",num);
if (!is_prime (num))
printf("not ");
printf("a prime number\n\n");
In your is_prime function you could have done this...
Code:
int is_prime (int p_num)
{ int i;
if ( ! (p_num & 1) ) // prime numbers are all odd numbers
return 0;
for(i = 3; i < p_num; i ++) // no need to check 1 or 2
if (p_num%i==0)
return 0;
return 1; }
There are always other ways of doing things...