Advertisement
lighted

Prime number check with function

Feb 25th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool isprime(int n)
  6. {
  7.     if (n == 1)
  8.         return false;
  9.  
  10.     for (int i = 2; i * i <= n; i++)
  11.         if (n % i == 0)
  12.             return false;
  13.  
  14.     return true;
  15. }
  16.  
  17. int main()
  18. {
  19.     int n;
  20.  
  21.     cin >> n;
  22.  
  23.     if (isprime(n))
  24.         cout << "prime" << endl;
  25.     else
  26.         cout << "composite" << endl;
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement