now I have never posted before so I hope this is in the right spot/format..
this problem is driving me insane. I need prove the Goldbach conjecture that is, "every even integer n > 2 is equal to the sum of 2 prime numbers." Then with a starting point and ending point prove this. (Ei: start at 2 end at 10 => 2 = 1 +1, 4 = 1 + 3....10 = 5 + 5)
The problem that I have is that I cant seem to figure out what is wrong with my code. When I run it the loop jumps over some intervals that it couldn't find a prime for and I just don't really know how to fix this as well as making the intervals go up 2 instead of 1 without a syntax error.
now this is what I have so far...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* function to create a random number */
int randomInteger(int low, int high)
{
static short firstRun = 1;
int offset;
if(firstRun)
{
//If this is the first call to this procedure, randomize the seed
srand(time(NULL));
//and set first run to 0 so we know its been run
firstRun = 0;
}
offset = low;
low = 0;
high -=offset;
return ((rand()%high)+offset);
}
/* function to see if a number is prime */
int prime_check(int num)
{
int i;
int check = 0;
for(i=1;i<=num;i++)
{
if(num % i == 0)
{
check = check +1;
}
}
if(check == 2)
/* printf("number is prime\n"); */
return 1;
else
/*printf("number is not prime\n");*/
return 0;
}
int main()
{
int a,b,i;
int prime1, prime2;
int start = 2;
int end = 20;
for(i = start; i <= end; i++)
{
prime1 = randomInteger(1,i);
a = prime_check(prime1);
if(a==1)
{
prime2 = (i - prime1);
b = prime_check(prime2);
if(b==1)
printf("%d = %d + %d\n", i, prime1, prime2);
else
randomInteger(1,i);
}
else
randomInteger(1,i);
/*lets me see what numbers the program skipped*/
printf("%d\n", i);
}
return 0;
}
when I compile and run it I get something that looks like this...
2
3
4 = 2 +2
5 = 3 +2
6
7 = 5 + 2
8 = 5 + 3
9
10 = 5 +5
11
12
13
14 = 7 +7
15
16
17
18 = 5 + 13
19 = 17 + 2
20