home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Utilities / top-0.5-MI / prime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-02  |  458 b   |  41 lines

  1. /*
  2.  * Prime number generator.  It prints on stdout the next prime number
  3.  * higher than the number specified as argv[1].
  4.  */
  5.  
  6. #include <math.h>
  7.  
  8. main(argc, argv)
  9.  
  10. int argc;
  11. char *argv[];
  12.  
  13. {
  14.     double i, j;
  15.     int f;
  16.  
  17.     if (argc < 2)
  18.     {
  19.     exit(1);
  20.     }
  21.  
  22.     i = atoi(argv[1]);
  23.     while (i++)
  24.     {
  25.     f=1;
  26.     for (j=2; j<i; j++)
  27.     {
  28.         if ((i/j)==floor(i/j))
  29.         {
  30.         f=0;
  31.         break;
  32.         }
  33.     }
  34.     if (f)
  35.     {
  36.         printf("%.0f\n", i);
  37.         exit(0);
  38.     }
  39.     }
  40. }
  41.