#include <stdio.h>

int is_prime (int);
/* Function returns 1 if the number is prime and 0 otherwise */

int main(int argc, char **argv)
{
    int num;  /* number user types */
	int no_read; /* how many integers user has typed */
	printf ("Give me a number > 1 to test: ");
	no_read= scanf("%d",&num);
	
	if (no_read != 1 || num <=1) {
		printf ("Input error!\n");
	}
	if (is_prime(num)) {
		printf ("%d is prime.\n",num);
	} else {
		printf ("%d is not prime.\n",num);
	}
    return 0;
}

int is_prime (int num)
/* This function takes one argument "num" it returns 1 if num is a prime
number and 0 if num is NOT a prime number.  Remember that in C, 0 means
FALSE and 1 means TRUE.*/
{

	int i;
	if (num < 2)		// There are no primes less than two
		return 0;
	for (i=2; i <= num/2; i++) {
		if (num %i == 0)  {
			return 0;
		}
	}
	return 1;
}

