Posted By

jholderman on 04/25/13


Tagged

number prime isPrime


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

danfinrud55


Is this Number Prime


 / Published in: C#
 

Method to Check if an int is a Prime Number

  1. static bool isPrime(int number)
  2. {
  3.  
  4. if (number == 1) return true;
  5. if (number == 2) return true;
  6. if (number == 3) return true;
  7. if (number == 4) return false;
  8.  
  9. for (int i = 2; i <= Math.Ceiling(Math.Sqrt(Convert.ToDouble(number))); i++)
  10. {
  11. if (number % i == 0)
  12. {
  13. return false;
  14. }
  15. }
  16.  
  17. return true;
  18.  
  19. }

Report this snippet  

You need to login to post a comment.