To Minipa: you are not wrong but that is not the cause of the infinite loop, the first loop iswhile(num < lim)and in line 16 of the first post {cout<<num<<endl;c=2;num++;}
To Croco: expected output is : 1,5,7,11,13.......1997,1999. if lim=2000
#include <iostream>
bool isPrime(constint& num)
{
if ( num < 2 )
returnfalse;
for(int a = 2 ; a < num ;a++)
{
if( num % a == 0 )
{
returnfalse;
}
}
returntrue;
}
int main()
{
int number;
std::cout << "Enter your number ";
std::cin >> number;
for (int i = 0; i < number; i++)
{
if ( isPrime(i) )
std::cout << i << " ";
}
std::cout << std::endl;
std::cin.get();
return 0;
}