home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l224 / 2.img / TFEXMPL2.ZIP / PRIME3.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-29  |  380 b   |  30 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, limit;
  13.  
  14.     limit = root(n);
  15.     for (i=2; i <= limit; i++)
  16.         if (n % i == 0)
  17.             return 0;
  18.     return 1;
  19. }
  20.  
  21. main()
  22. {
  23.     int i, n;
  24.  
  25.     n = 1000;
  26.     for (i=2; i<=n; i++)
  27.         if (prime(i))
  28.             printf("%d\n", i);
  29. }
  30.