#include<stdio.h>

int is_prime (int);
/* Program works out sums for goldbach's conjecture */

int main(int argc, char **argv)
{
    int max= 100;   // Check goldbach conjecture up to this value
	int i,j;

	for (i= 4; i <= max; i+=2) {  // i is the number we check
		for (j=3; j <= i/2; j+=2) {  // j and i-j are the numbers
								// to be tested to make the sum
			if (is_prime(j) && is_prime(i-j)) {
				printf ("%d + %d = %d  is a prime sum\n",
					j, i-j, i);
				break;
			}
		}
		if (j > max/2) {
			printf ("Exception to conjecture found!\n");
			printf ("No sum found for %d\n",i);
			break;
		}
	}
    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.*/
{
	static called= 0;  //# of times routine has been called
	int i;
	called= called+1;
	printf ("is_prime called %d times\n",called);
	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;
}

