Sum of two adjacent numbers are primes: Difference between revisions

Content added Content deleted
(Realize in F#)
(Added Algol 68)
Line 4: Line 4:
<br>
<br>
Show on this page the first 20 numbers and sum of two adjacent numbers which sum is prime.
Show on this page the first 20 numbers and sum of two adjacent numbers which sum is prime.

=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find the first 20 primes which are n + ( n + 1 ) for some n #
PR read "primes.incl.a68" PR # include prime utilities #
[]BOOL prime = PRIMESIEVE 200; # should be enough primes #
INT p count := 0;
FOR n WHILE p count < 20 DO
INT n1 = n + 1;
INT p = n + n1;
IF prime[ p ] THEN
p count +:= 1;
print( ( whole( n, -2 ), " + ", whole( n1, -2 ), " = ", whole( p, -3 ), newline ) )
FI
OD
END</lang>
{{out}}
<pre>
1 + 2 = 3
2 + 3 = 5
3 + 4 = 7
5 + 6 = 11
6 + 7 = 13
8 + 9 = 17
9 + 10 = 19
11 + 12 = 23
14 + 15 = 29
15 + 16 = 31
18 + 19 = 37
20 + 21 = 41
21 + 22 = 43
23 + 24 = 47
26 + 27 = 53
29 + 30 = 59
30 + 31 = 61
33 + 34 = 67
35 + 36 = 71
36 + 37 = 73
</pre>


=={{header|C}}==
=={{header|C}}==