Advertisement
Guest User

Untitled

a guest
Dec 27th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. /**
  2. * Requires math.h
  3. * Returns 1 if num is prime else returns 0.
  4. */
  5. int is_prime(int num) {
  6. if (num <= 2) return 0;
  7. if (num == 2) return 1;
  8. if (num%2 == 0) return 0;
  9. for (int i=3; i<=sqrt(num); i+=2) {
  10. if (num%i == 0) return 0;
  11. }
  12. return 1;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement