home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l224 / 2.img / TFEXMPL2.ZIP / PRIME2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-29  |  356 b   |  29 lines

  1. /* Copyright (c) 1990, Borland International */
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. root(int n)
  6. {
  7.     return (int) sqrt((float) n);
  8. }
  9.  
  10. prime(int n)
  11. {
  12.     int i;
  13.  
  14.     for (i=2; i <= root(n); i++)
  15.         if (n % i == 0)
  16.             return 0;
  17.     return 1;
  18. }
  19.  
  20. main()
  21. {
  22.     int i, n;
  23.  
  24.     n = 1000;
  25.     for (i=2; i<=n; i++)
  26.         if (prime(i))
  27.             printf("%d\n", i);
  28. }
  29.