Display all the prime numbers between 2 numbers

Mar 4, 2012 at 3:33pm
#include <iostream>
#include <ctime>
#include <cmath>

void primeNumbers (int num1, int num2){
//find the prime numbers between num1 and num2

if statements or a loop

//display the numbers
return?
}
int main () {

primeNumber(5,10);
system ("pause")
return 0;

}

Mar 4, 2012 at 3:58pm
What's your question?
Mar 4, 2012 at 4:04pm
Stuck on the if statement and the loop
Mar 4, 2012 at 4:06pm
loop through all numbers between the lower number and the bigger number.
- if prime, output it
- if not prime, don't
Mar 4, 2012 at 4:23pm
#include <iostream>
#include <ctime>
#include <cmath>

void primeNumbers (int num1, int num2){
//find the prime numbers between num1 and num2

{
for (int i=2; i<100; i++)
for (int j=2; j<i; j++)
{
if (i % j == 0)
break;
else if (i == j+1);
cout << i << " ";


//display the numbers
return;
}
int main () {

primeNumber(5,10);
system ("pause")
return 0;
Last edited on Mar 5, 2012 at 3:27pm
Mar 4, 2012 at 4:25pm
return?
That's wrong. it should be return;

Was that your question?
Mar 5, 2012 at 3:42pm
This code i ave still cant get it working
Mar 7, 2012 at 12:15am
Can someone give me a hand with my loop in this code
Mar 8, 2012 at 4:36am
Your brackets are all over the place dude.
Mar 8, 2012 at 4:54am
This thread is just like this one:
http://www.cplusplus.com/forum/beginner/63859/

Maybe that'll help you out a bit....
Mar 8, 2012 at 5:04am
Yes except that question was asked properly. Ken777, it is extremely offensive to the helpers of this forum if you just copy paste a code straight from your homework sheet and make no attempt to structure your question. The forum rules are clear on this note. If you had followed the guidelines you probably would have a working program right now.
Topic archived. No new replies allowed.