What is wrong with my code? Itâs working on mine but it doesnât accept my solution.
// SPOJ PRIME1 - Prime Generator
#include
using namespace std;
// Checks if prime or not
bool checkPrime(long j)
{
int checker = 0;
if (j > 1)
{
for (int i = 2; i <= 10; i++)
{
if (j % i == 0)
{
checker++;
}
}
if (checker > 1)
return false;
else if (checker == 1)
return true;
else
return false;
}
else
return false;
}
int main()
{
// Input
int step;
do
{
cin >> step;
}
while (step > 10);
// Iterates each step
for (int i = 0; i < step; i++)
{
long m, n;
cin >> m >> n;
// Iterates from m to n
for (int j = m; j <= n; j++)
{
bool isPrime = checkPrime(j);
if (isPrime)
cout << j << endl;
}
cout << endl;
}
return 0;
}