Advertisement
Alx09

prime

Feb 19th, 2022 (edited)
1,569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6.  
  7. int main()
  8. {
  9.     int x, y;
  10.     bool isPrime;
  11.     cin >> x >> y;
  12.     if(y < 2) return 0;
  13.     x++;
  14.     if( x < 2)  x = 2;
  15.     for( ; x < y; x++){
  16.  
  17.         isPrime = true;
  18.         for(int j = 2; j <= x / 2; j++){
  19.             if(x % j == 0){
  20.                 isPrime = false;
  21.                 break;
  22.             }
  23.         }
  24.  
  25.          if(isPrime)
  26.                 cout << x << ' ';
  27.  
  28.     }
  29.  
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement