| | |
prime numbers
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 4
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- (Noob) need some help w/ Prime Numbers (C++)
- Prime Numbers (C)
- prime numbers homework trouble (C++)
- help with array that determines prime numbers (C)
- prime numbers (C++)
Other Threads in the C++ Forum
- Previous Thread: need help with an IF statement
- Next Thread: couple of bugs, suggestions welcomed
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





