rakcode1998

Untitled

Apr 11th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. bool isprime(int n)
  2.     {
  3.         if(n==1 || (n%2==0 && n!=2))
  4.         {
  5.             return false;
  6.         }
  7.         else if(n==2 || n==3)
  8.         {
  9.             return true;
  10.         }
  11.         else
  12.         {
  13.             int res=0;
  14.             for(int i=3 ;i<=(int)sqrt(n) ;i+=2)
  15.             {
  16.                 if(n%i==0)
  17.                 {
  18.                     res++;
  19.                     break;
  20.                 }
  21.             }
  22.  
  23.             if(res==0)
  24.             {
  25.                 return true;
  26.             }
  27.             else
  28.             return false;
  29.         }
  30.     }
Add Comment
Please, Sign In to add comment