Advertisement
Shuva_Dev

Check a number prime or not

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