#include <iostream>
#include <cmath>

bool esPrimo(int numero) {
    if (numero <= 1) return false;
    if (numero <= 3) return true;
    if (numero % 2 == 0 || numero % 3 == 0) return false;
    for (int i = 5; i * i <= numero; i += 6) {
        if (numero % i == 0 || numero % (i + 2) == 0) return false;
    }
    return true;
}

int main() {
    int N;
    std::cout << "Ingrese el valor de N: ";
    std::cin >> N;

    for (int i = 2; i <= N; ++i) {
        if (esPrimo(i)) {
            std::cout << i << " ";
        }
    }
    std::cout << std::endl;

    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: