Numbers whose binary and ternary digit sums are prime: Difference between revisions

(→‎{{header|GW-BASIC}}: GW-BASIC features applied (PRINT USING, MOD, WHILE... WEND etc.))
Line 296:
 
=={{header|BASIC}}==
==={{header|Chipmunk Basic}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="basic">
100 rem Numbers which binary and ternary digit sum are prime
110 for n = 2 to 199
120 if is_prime(digit_sum(n,2)) <> 0 then
130 if is_prime(digit_sum(n,3)) <> 0 then print using "### ";n;
140 endif
150 next n
160 print
170 end
180 sub is_prime(p)
190 if p = 3 or p = 2 then
200 is_prime = 1
210 else
220 if p = 1 then
230 is_prime = 0
240 else
250 q = 1 : i = 1
260 i = i+1
270 if p mod i = 0 then q = 0
280 if i*i <= p and q <> 0 then 260
290 is_prime = q
300 endif
310 endif
320 end sub
330 sub digit_sum(n,bas)
340 p = 0 : xn = n
350 while xn <> 0
360 p = p+xn mod bas
370 xn = int(xn/bas)
380 wend
390 digit_sum = p
400 end sub
</syntaxhighlight>
{{out}}
<pre>
5 6 7 10 11 12 13 17 18 19 21 25 28 31 33 35 36 37 41 47 49 55 59 61 65 67 69 73 79 82 84 87 91 93 97 103 107 109 115 117 121 127 129 131 133 137 143 145 151 155 157 162 167 171 173 179 181 185 191 193 199
</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">#include"isprime.bas"
512

edits