int num, i, is_prime;
printf("Enter a number: ");
scanf("%d", &num);
is_prime = 1;
for(i = 2; i <= num / 2; i = i + 1)
if((num%i)==0)
is_prime = 0;
if(is_prime==1)
printf(" is prime.");
else
printf("not prime.");
most of time we use
for(i = 2; i <= num / 2; i = i + 1)
if((num%i)==0){
is_prime = 0;
break; }
this stops the for loop as soon as the no is found not to be prime, save remaining iterations of loop