Summarize primes: Difference between revisions

Added XPL0 example.
(Added Algol W)
(Added XPL0 example.)
Line 1,296:
 
21 such prime sums found
</pre>
 
=={{header|XPL0}}==
<lang XPL0>func IsPrime(N); \Return 'true' if N is a prime number
int N, I;
[if N <= 1 then return false;
for I:= 2 to sqrt(N) do
if rem(N/I) = 0 then return false;
return true;
];
 
int Count, N, Sum, Prime;
[Text(0, "Prime Prime
count sum
");
Count:= 0; N:= 0; Sum:= 0;
for Prime:= 2 to 1000-1 do
if IsPrime(Prime) then
[N:= N+1;
Sum:= Sum + Prime;
if IsPrime(Sum) then
[Count:= Count+1;
IntOut(0, N);
ChOut(0, 9\tab\);
IntOut(0, Sum);
CrLf(0);
];
];
IntOut(0, Count);
Text(0, " prime sums of primes found below 1000.
");
]</lang>
 
{{out}}
<pre>
Prime Prime
count sum
1 2
2 5
4 17
6 41
12 197
14 281
60 7699
64 8893
96 22039
100 24133
102 25237
108 28697
114 32353
122 37561
124 38921
130 43201
132 44683
146 55837
152 61027
158 66463
162 70241
21 prime sums of primes found below 1000.
</pre>
772

edits