A number if prime if it is not divisible by other then 1 and self. So it means if given number is N and if we check from 2 to n-1 if number if not divisible by anyone then its prime. In practice if we do the same from 2 to n/2 then the above logic is suffice.
See the sample code -
#include <stdio.h>
#include <stdlib.h>
void main()
{
int n, i, isprime;
printf("Enter a number \n");
scanf("%d", &n);
if (n <= 1)
{
printf("%d is not a prime numbers \n", n);
exit(1);
}
isprime = 1;
for (i = 2; i <= n / 2; i++)
{
if ((n % i) == 0)
{
isprime = 0;
break;
}
}
if (isprime == 1)
printf("%d is a prime number \n", n);
else
printf("%d is not a prime number \n", n);
}