Sort primes from list to a list: Difference between revisions

Sort primes from list to a list en Yabasic
(Sort primes from list to a list en FreeBASIC)
(Sort primes from list to a list en Yabasic)
Line 117:
<pre>[2,7,13,43,103]</pre>
 
==={{header|Yabasic}}===
<lang yabasic>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 arraysize(Primes(),1)
if isPrime(Primes(n)) then
redim temp(c)
temp(c) = Primes(n)
c = c + 1
end if
next n
sort(temp)
showArray(temp)
end
 
sub isPrime(v)
if v < 2 then return False : fi
if mod(v, 2) = 0 then return v = 2 : fi
if mod(v, 3) = 0 then return v = 3 : fi
d = 5
while d * d <= v
if mod(v, d) = 0 then return False else d = d + 2 : fi
wend
return True
end sub
 
sub sort(array)
for i = 1 to arraysize(temp(),1)
for j = i + 1 to arraysize(temp(),1)
if temp(i) > temp(j) then
t = temp(i) : temp(i) = temp(j) : temp(j) = t
end if
next j
next i
end sub
 
sub showArray(array)
local txt$ //= ""
print "[";
for n = 1 to arraysize(temp(),1)
txt$ = txt$ + str$(temp(n)) + ","
next n
txt$ = left$(txt$,len(txt$)-1)
txt$ = txt$ + "]"
print txt$
end sub</lang>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
=={{header|F_Sharp|F#}}==
2,131

edits