### Prime numbers in a given range

I have an assignment where I have to use two for loops. I need to ask the user for any two numbers and be able to list all the numbers in between and their factors and state whether or not the number is prime or not. Can anyone help me because I do not really know where to start.
Thanks!!
Simply for you to use. Actually you should try you own version, this is a very simple solution.
#include<iostream>
using namespace std;

int main()
{
int a = 1, b = 1;
while (a <=1 || b <= 1)
{
cout << "please enter a number for a : ";
cin >> a;

cout << "please enter a number for b :";
cin >> b;

if (a <=1 || b <=1)
{
cout << "the number you enter not good enough for use : [< 2]" << endl;
}
}
if (a > b)
{
int c = b;
b = a;
a = c;
}

for (int i = a; i <= b; ++i)
{
int bprime = true;
for (int j = 2; j < i; ++j)
{
if (i != j && (i % j == 0))
{
cout << i << "is a not prime number" << endl;
bprime = false;
break;
}
}
if (bprime)
{
cout << i << "is a prime number" << endl;
}
}

}
Topic archived. No new replies allowed.