Habsburg

peti

Apr 14th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int A = 0, B = 0;
  8.     srand(time(NULL));
  9.     do {
  10.         cout << "Upisite A: \n";
  11.         cin >> A;
  12.         cout << "Upisite B: \n";
  13.         cin >> B;
  14.     }while(A < 1  || B < 1);
  15.    
  16.     bool pronadjen = false;
  17.     bool prost = false;
  18.     int randBroj = 0;
  19.     while(!pronadjen) {
  20.         prost = true;
  21.         randBroj = rand() % B + A;
  22.         for(int i = 2; i < randBroj; ++i)
  23.             if(randBroj % i == 0) {
  24.                 prost = false;
  25.                 break;
  26.             }
  27.         if(prost)
  28.             pronadjen = true;
  29.     }
  30.     cout << randBroj << endl;
  31.    
  32.    
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment