eratos.pp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. {****************************************************************************
  2. $Id$
  3. Copyright (c) 1993,94 by Florian Kl„mpfl
  4. Translated By Eric Molitor ([email protected])
  5. ****************************************************************************}
  6. { Demonstration Program in FPKPascal }
  7. { Calculates all Prime Numbers from 1 to max }
  8. program eratosthenes;
  9. const
  10. max = 1000000;
  11. var
  12. a : array[1..max] of boolean;
  13. procedure eratos;
  14. var
  15. i,j : longint;
  16. begin
  17. a[1]:=false;
  18. for i:=1 to max do
  19. a[i]:=true;
  20. for i:=2 to max div 2 do
  21. if a[i] then
  22. for j:=2 to max div i do
  23. a[i*j]:=false;
  24. writeln;
  25. for i:=1 to max do
  26. if a[i] then
  27. write(i:8);
  28. writeln;
  29. end;
  30. begin
  31. write('Calculating the Prime Numbers from 1 to ',max,'...');
  32. eratos;
  33. end.
  34. {
  35. $Log$
  36. Revision 1.4 1998-09-04 17:38:15 pierre
  37. * the algorythm was wrong (unnecessary checks were made)
  38. Revision 1.3 1998/04/06 12:23:21 pierre
  39. * log problem
  40. Revision 1.2 1998/04/06 12:17:00 pierre
  41. * made array a global to avoid stack overflow
  42. }