Sum of two adjacent numbers are primes: Difference between revisions

Added C.
(Added Wren)
(Added C.)
Line 4:
<br>
Show on this page the first 20 numbers and sum of two adjacent numbers which sum is prime.
 
=={{header|C}}==
{{trans|Wren}}
<lang c>#include <stdio.h>
 
#define TRUE 1
#define FALSE 0
 
int isPrime(int n) {
if (n < 2) return FALSE;
if (!(n%2)) return n == 2;
if (!(n%3)) return n == 3;
int d = 5;
while (d*d <= n) {
if (!(n%d)) return FALSE;
d += 2;
if (!(n%d)) return FALSE;
d += 4;
}
return TRUE;
}
 
int main() {
int count = 0, n = 1;
printf("The first 20 pairs of natural numbers whose sum is prime are:\n");
while (count < 20) {
if (isPrime(2*n + 1)) {
printf("%2d + %2d = %2d\n", n, n + 1, 2*n + 1);
count++;
}
n++;
}
return 0;
}</lang>
 
{{out}}
<pre>
The first 20 pairs of natural numbers whose sum is prime are:
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|Raku}}==
9,483

edits