Advertisement
DidiMilikina

10. Check Prime

Oct 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n;
  8.     cin >> n;
  9.     bool prime = true;
  10.     if (n >= 2)
  11.     {
  12.  
  13.  
  14.         for (size_t i = 2; i <= sqrt(n); i++)
  15.             if (n % i == 0) {
  16.                 prime = false;
  17.                 break;
  18.             }
  19.         if (prime) cout << "Prime" << endl;
  20.         else cout << "Not prime" << endl;
  21.     }
  22.     else cout << "Not prime" << endl;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement