Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int main() {
- int A = 0, B = 0;
- srand(time(NULL));
- do {
- cout << "Upisite A: \n";
- cin >> A;
- cout << "Upisite B: \n";
- cin >> B;
- }while(A < 1 || B < 1);
- bool pronadjen = false;
- bool prost = false;
- int randBroj = 0;
- while(!pronadjen) {
- prost = true;
- randBroj = rand() % B + A;
- for(int i = 2; i < randBroj; ++i)
- if(randBroj % i == 0) {
- prost = false;
- break;
- }
- if(prost)
- pronadjen = true;
- }
- cout << randBroj << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment