This problem is kinda like the Goldbach's conjecture

When I input a number n the program is supposed to show the nth sum of two primes. According to the Goldbach's conjecture, all even numbers can be made with the sum of two primes, so now we have to find the right odd numbers. We know that all primes are odd numbers except for 2 but since odd+even=odd number all odd sums two prime numbers would have to be added with 2. I think this is all we have to know to make this. But my C++ sucks so please help out. Thanks guys!


#include <iostream>

using namespace std;

int main() {


int i,j,k,l=0;

cout<<"Enter a Number: ";
cin>>i;

for(j=4; j<i; j++)
{
if(j%2==0) i++;
else {
for(k=2; k<=((j-2)/2); k++)
{
if((j-2)%k==0)
{
l=1;
}
}
if (l==0)
i++;
}
}
cout<<j<<endl;
}
Topic archived. No new replies allowed.