Author: Not specified Language: c
Description: Not specified Timestamp: 2013-06-20 14:00:23 +0000
View raw paste Reply
  1. /******************************
  2.  * tests if a number is prime *
  3.  ******************************/
  4. int isprime(n)
  5. {
  6.         int x;
  7.         int squared;
  8.         squared = pow(n,0.5);
  9.  
  10.         if (n < 2)
  11.                 return 0;
  12.         if (n == 2)
  13.                 return 1;
  14.         if (n % 2 == 0)
  15.                 return 0;
  16.         for (x = 3; (x < (squared + 1)); x = x + 2)
  17.                 if (n % x == 0)
  18.                         return 0;
  19.         return 1;
  20. }
View raw paste Reply