Summarize primes: Difference between revisions
Content deleted Content added
No edit summary |
Added BASIC256, Chipmunk Basic, Gambas, PureBasic and Yabasic |
||
Line 320: | Line 320: | ||
Summarized primes 1-999: 21 |
Summarized primes 1-999: 21 |
||
</pre> |
</pre> |
||
=={{header|BASIC}}== |
|||
==={{header|BASIC256}}=== |
|||
<syntaxhighlight lang="vb">#include "isprime.kbs" |
|||
print 1, 2, 2 |
|||
sum = 2 |
|||
n = 1 |
|||
for i = 3 to 999 step 2 |
|||
if isPrime(i) then |
|||
sum += i |
|||
n += 1 |
|||
if isPrime(sum) then |
|||
print n, i, sum |
|||
end if |
|||
end if |
|||
next i</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as FreeBASIC entry.</pre> |
|||
==={{header|FreeBASIC}}=== |
|||
<syntaxhighlight lang="freebasic">#include "isprime.bas" |
|||
print 1,2,2 |
|||
dim as integer sum = 2, i, n=1 |
|||
for i = 3 to 999 step 2 |
|||
if isprime(i) then |
|||
sum += i |
|||
n+=1 |
|||
if isprime(sum) then |
|||
print n, i, sum |
|||
end if |
|||
end if |
|||
next i</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1 2 2 |
|||
2 3 5 |
|||
4 7 17 |
|||
6 13 41 |
|||
12 37 197 |
|||
14 43 281 |
|||
60 281 7699 |
|||
64 311 8893 |
|||
96 503 22039 |
|||
100 541 24133 |
|||
102 557 25237 |
|||
108 593 28697 |
|||
114 619 32353 |
|||
122 673 37561 |
|||
124 683 38921 |
|||
130 733 43201 |
|||
132 743 44683 |
|||
146 839 55837 |
|||
152 881 61027 |
|||
158 929 66463 |
|||
162 953 70241</pre> |
|||
==={{header|Gambas}}=== |
|||
<syntaxhighlight lang="vbnet">Use "isprime.bas" |
|||
Public Sub Main() |
|||
Print 1, 2, 2 |
|||
Dim n As Integer = 1, i As Integer, sum As Integer = 2 |
|||
For i = 3 To 999 Step 2 |
|||
If isPrime(i) Then |
|||
sum += i |
|||
n += 1 |
|||
If isPrime(sum) Then |
|||
Print n, i, sum |
|||
End If |
|||
End If |
|||
Next |
|||
End</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as FreeBASIC entry.</pre> |
|||
==={{header|PureBasic}}=== |
|||
<syntaxhighlight lang="vb">;XIncludeFile "isprime.pb" |
|||
OpenConsole() |
|||
Define.i sum, i, n |
|||
PrintN("1" + #TAB$ + "2" + #TAB$ + "2") |
|||
sum = 2 |
|||
n = 1 |
|||
For i = 3 To 999 Step 2 |
|||
If isPrime(i): |
|||
sum + i |
|||
n + 1 |
|||
If isPrime(sum): |
|||
PrintN(Str(n) + #TAB$ + Str(i) + #TAB$ + Str(sum)) |
|||
EndIf |
|||
EndIf |
|||
Next i |
|||
Input() |
|||
CloseConsole()</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as FreeBASIC entry.</pre> |
|||
==={{header|Yabasic}}=== |
|||
<syntaxhighlight lang="vb">//import isprime |
|||
print 1, chr$(9), 2, chr$(9), 2 |
|||
sum = 2 |
|||
n = 1 |
|||
for i = 3 to 999 step 2 |
|||
if isPrime(i) then |
|||
sum = sum + i |
|||
n = n + 1 |
|||
if isPrime(sum) print n, chr$(9), i, chr$(9), sum |
|||
fi |
|||
next i |
|||
end</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as FreeBASIC entry.</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |
||
Line 673: | Line 790: | ||
{{out}} |
{{out}} |
||
<pre>count prime sum |
|||
<pre> |
|||
count prime sum |
|||
1 2 2 |
1 2 2 |
||
2 3 5 |
2 3 5 |
||
Line 695: | Line 811: | ||
152 881 61027 |
152 881 61027 |
||
158 929 66463 |
158 929 66463 |
||
162 953 70241 |
162 953 70241</pre> |
||
</pre> |
|||
=={{header|FreeBASIC}}== |
|||
<syntaxhighlight lang="freebasic">#include "isprime.bas" |
|||
print 1,2,2 |
|||
dim as integer sum = 2, i, n=1 |
|||
for i = 3 to 999 step 2 |
|||
if isprime(i) then |
|||
sum += i |
|||
n+=1 |
|||
if isprime(sum) then |
|||
print n, i, sum |
|||
end if |
|||
end if |
|||
next i</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1 2 2 |
|||
2 3 5 |
|||
4 7 17 |
|||
6 13 41 |
|||
12 37 197 |
|||
14 43 281 |
|||
60 281 7699 |
|||
64 311 8893 |
|||
96 503 22039 |
|||
100 541 24133 |
|||
102 557 25237 |
|||
108 593 28697 |
|||
114 619 32353 |
|||
122 673 37561 |
|||
124 683 38921 |
|||
130 733 43201 |
|||
132 743 44683 |
|||
146 839 55837 |
|||
152 881 61027 |
|||
158 929 66463 |
|||
162 953 70241</pre> |
|||
=={{header|Fōrmulæ}}== |
=={{header|Fōrmulæ}}== |
||
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation —i.e. XML, JSON— they are intended for storage and transfer purposes more than visualization and edition. |
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation —i.e. XML, JSON— they are intended for storage and transfer purposes more than visualization and edition. |
||