#include <iostream>
#include <cmath>
using namespace std;
bool prime(int j);
int main()
{int m;
int n;
int ok;
do
{
cout<< "insert number with which the serie of number will start:" << endl;
cin >> m;
cout << "insert number with which the serie of numbers will end:" << endl;
cin>> n;
cout << "the primes of this serie of number are"<< endl;
for(int j = n; j <= m; j++)
{
if (prime(j)==true)
cout << j;
}
cout << "continue(1) or end(0)?" << endl;
cin>>ok;
}while(ok==1);
insert number with which the serie of number will start:
100
insert number with which the serie of numbers will end:
2
the primes of this serie of number are
2357111317192329313741434753596167717379838997continue(1) or end(0)?
0
#include <iostream>
#include <cmath>
usingnamespace std;
bool prime(int j);
int main()
{int m;
int n;
int ok;
do
{
cout<< "Please insert the number with which the series of number will start(Smaller):" << endl;
cin >> n;
cout << "Please insert the number with which the series of numbers will end(Larger):" << endl;
cin>> m;
cout << "The primes of this series of number are"<< endl;
for(int j = n; j <= m; j++)
{
if (prime(j)==true)
cout << j<<", ";
}
cout << "\ncontinue(1) or end(0)?" << endl;
cin>>ok;
}while(ok==1);
return 0;}
bool prime(int j)
{
if (j < 2) returnfalse;
for(int i=2; i<= sqrt(j); i++) {
if ((j%i) == 0) returnfalse;
}
returntrue;}
You should invest in looking at the Sieve of Eratosthenes. There are other ways to improve the efficiency of yours though, instead of <= sqrt(j) you can do i*i <=j <= j*j then instead of incrementing by 1 you can increment by 2 and start at 3 instead of 2. You would of course return false if the first bit was set before the loop though. But again, I suggest using a prime sieve.