Sort primes from list to a list: Difference between revisions

Sort primes from list to a list en BASIC256
(Sort primes from list to a list en Yabasic)
(Sort primes from list to a list en BASIC256)
Line 71:
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<lang BASIC256>arraybase 1
global temp
 
function isPrime(v)
if v < 2 then return False
if v mod 2 = 0 then return v = 2
if v mod 3 = 0 then return v = 3
d = 5
while d * d <= v
if v mod d = 0 then return False else d += 2
end while
return True
end function
 
subroutine sort(array)
for i = 1 to array[?]
for j = i + 1 to array[?]
if temp[i] > temp[j] then
t = temp[i] : temp[i] = temp[j] : temp[j] = t
end if
next j
next i
end subroutine
 
subroutine showArray(array)
txt$ = ""
print "[";
for n = 1 to array[?]
txt$ &= string(array[n]) & ","
next n
txt$ = left(txt$,length(txt$)-1)
txt$ &= "]"
print txt$
end subroutine
 
dim Primes(9)
Primes[1] = 2
Primes[2] = 43
Primes[3] = 81
Primes[4] = 122
Primes[5] = 63
Primes[6] = 13
Primes[7] = 7
Primes[8] = 95
Primes[9] = 103
c = 1
 
for n = 1 to Primes[?]
if isprime(Primes[n]) then
redim temp(c)
temp[c] = Primes[n]
c += 1
end if
next n
call sort(temp)
call showArray(temp)
end</lang>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
==={{header|FreeBASIC}}===
<lang freebasic>Dim Shared As Integer temp()
2,148

edits