/* Program by: Jeremy
 * Date: 11/4/2004
 * Objective: Determine if a given number is prime.
 */

#include <stdio.h>

int isprime(unsigned int);

int main() {
	unsigned int number=1;
	for(;;) {
		printf("\nInput a number to test if it is prime:");
		scanf("%u",&number);
		if (number == 0){
			printf("Thanks.\n");
			return 0;
		}

		if (isprime(number))
			printf("The number %u is prime.\n",number);
		else
			printf("The number %u is NOT prime.\n",number);
	}
	return 0;
}

int isprime(unsigned int num) {
	int half,i;
	if (num < 4)
		return 1;
	if (!(num % 2))
		return 0;
	
	half = (num + 1) / 2;
	for(i=3; i< half; i+=2) {
		if(!(num % i))  
			return 0;
	}
	return 1;
}