#include <iostream>
#include <cmath>
bool isprime(int maxno)
{
if (maxno < 3 || maxno % 2 == 0)
return maxno == 2;
for (int i = 3, maxtry = static_cast<int>(sqrt(maxno)); i <= maxtry; i += 2)
if (maxno % i == 0)
returnfalse;
returntrue;
}
int main()
{
int pmax {};
std::cout << "Enter the maximum number for primes: ";
std::cin >> pmax;
std::cout << 2;
for (int p = 3; p < pmax; p += 2)
if (isprime(p))
std::cout << ' ' << p;
std::cout << '\n';
}
bool isprime(int maxno)
{
if (maxno < 3 || maxno % 2 == 0)
return maxno == 2;
for (int i = 3; i * i <= maxno; i += 2)
if (maxno % i == 0)
returnfalse;
returntrue;
}