identification division.
program-id. primes.
* aus Wirth, systematisches Programmieren p. 134
author. "JD".
date-written. 11.9.2005.
date-compiled.
environment division.
input-output section.
file-control.
select f assign to file-f
status f-status.
data division.
file section.
fd f
record contains 120 characters
data record is f-record
label record is omitted.
01 f-record.
05 i pic x(8).
working-storage section.
78 n value 100.
77 f-status pic S9(4) comp.
77 nroot pic 9(4) value 10.
77 x pic 9(4).
77 square pic 9(4).
77 i pic 9(4).
77 k pic 9(4).
77 lim pic 9(4).
77 prim.
88 prim-true value 1.
88 prim-false value 0.
77 p pic 9(4) occurs n.
77 v pic 9(4) occurs n.
procedure division.
* find first n prime numbers
move 2 to p(1)
move 2 to i write f-record
move 1 to x lim
move 4 to square
perform varying i from 2 until i = n
perform until prim-true
add 2 to x
if square <= x then
move square to v(lim)
add 1 to lim
compute square = p(lim)*p(lim)
end-if
move 2 to k
set prim-true to true
perform until not prim-true or (k <= lim)
if v(k) < x then
add p(k) to v(k)
end-if
if x not=v(k) then set prim-true to true end-if
add 1 to k
end-perform
end-perform
move x to p(i)
write f-record from x
end-perform.
fin.
* x(1) ... x(n) sind die Lösungen
stop run.
end-program primes.
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
|
Haftungshinweis
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.
|