i wrote this program to find prime numbers, but whenever i run it, i get an error.
This is the code [c++]:
int main(void)
{
int num=0;
int i=0;
cout<<"num";
cin>>num;
while(i<num)
{
num=num%i;
i++;
}
if(num==0)
cout<<"not prime";
else
cout<<"prime";
return 0;
}
My real task is to get the user to input a number greater than 2, and then print out what prime numbers added together would make up the number the user inputed. For example:
4 = 2 + 2
6 = 3 + 3
8 = 3 + 5
10 = 3 + 7 etc.
i need to create a function: void Goldbach(int n, int& p1, int & p2)
and the main program would be:
void main()
{
int num, prime1, prime2;
cout<<"Enter an even positive integer greater than 2:";
cin>>num;
Goldbach(num,prime1,prime2);
cout<<num<<" = "<<prime1<<" + "<<prime2<<endl;
}
//my first step is to determine what 2 prime numbers would add up to get the //number the user inputs.
Edit/Delete Message