#include <iostream>
#include<vector>

bool DaLiJeProst(int n){
    if(n < 2 || n != 2 && n % 2 == 0) return false;

    for(int i = 3; i < n / i; i++)
        if(n % i == 0) return false;
    return true;
}

std::vector<int> ProstiBrojeviUOpsegu(int a, int b){
    std::vector<int> v;
    for(int i = a; i <= b; i++){
        if(DaLiJeProst(i)) v.push_back(i);
        if(i == b) break;
    }
    return v;
}
int main() {
     int p=0, q=0; 
std::cout << "Unesite pocetnu i krajnju vrijednost: "; 
std::cin >> p >> q; 
auto v = ProstiBrojeviUOpsegu(p, q); 
if(v.size() == 0) 
std::cout << "Nema prostih brojeva u rasponu od " << p << " do " << q << "!\n"; 
else { 
std::cout << "Prosti brojevi u rasponu od " << p << " do " << q << " su: "; 
for(int i = 0; i < v.size(); i++) 
std::cout << v[i] << (i != v.size() - 1 ? ", " : "\n"); 
} 
    return 0;
}

Embed on website

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