Largest proper divisor of n: Difference between revisions
Content added Content deleted
(add RPL) |
(Grouping BASIC dialects) |
||
Line 503: | Line 503: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 1 1 1 2 1 3 1 4 3 5 |
|||
<pre> |
|||
1 1 1 2 1 3 1 4 3 5 |
|||
1 6 1 7 5 8 1 9 1 10 |
1 6 1 7 5 8 1 9 1 10 |
||
7 11 1 12 5 13 9 14 1 15 |
7 11 1 12 5 13 9 14 1 15 |
||
Line 515: | Line 514: | ||
13 46 31 47 19 48 1 49 33 50 |
13 46 31 47 19 48 1 49 33 50 |
||
Largest proper divisor of n 1-100 |
Largest proper divisor of n 1-100</pre> |
||
</pre> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
{{works with|QBasic|1.1}} |
|||
{{works with|QuickBasic|4.5}} |
|||
<syntaxhighlight lang="basic">10 DEFINT A-Z |
<syntaxhighlight lang="basic">10 DEFINT A-Z |
||
20 FOR I=1 TO 100 |
20 FOR I=1 TO 100 |
||
Line 539: | Line 539: | ||
13 46 31 47 19 48 1 49 33 50</pre> |
13 46 31 47 19 48 1 49 33 50</pre> |
||
=={{header|BASIC256}}== |
==={{header|BASIC256}}=== |
||
{{trans|FreeBASIC}} |
{{trans|FreeBASIC}} |
||
<syntaxhighlight lang="basic256">print "El mayor divisor propio de n es:\n" |
<syntaxhighlight lang="basic256">print "El mayor divisor propio de n es:\n" |
||
Line 554: | Line 554: | ||
end</syntaxhighlight> |
end</syntaxhighlight> |
||
==={{header|FreeBASIC}}=== |
|||
<syntaxhighlight lang="freebasic">Print !"El mayor divisor propio de n es:\n" |
|||
Print " 1 1"; |
|||
For i As Byte = 3 To 100 |
|||
For j As Byte = i-1 To 1 Step -1 |
|||
If i Mod j = 0 Then Print Using "###"; j; : Exit For |
|||
Next j |
|||
If i Mod 10 = 0 Then Print |
|||
Next i |
|||
Sleep</syntaxhighlight> |
|||
{{out}} |
|||
<pre>El mayor divisor propio de n es: |
|||
1 1 1 2 1 3 1 4 3 5 |
|||
1 6 1 7 5 8 1 9 1 10 |
|||
7 11 1 12 5 13 9 14 1 15 |
|||
1 16 11 17 7 18 1 19 13 20 |
|||
1 21 1 22 15 23 1 24 7 25 |
|||
17 26 1 27 11 28 19 29 1 30 |
|||
1 31 21 32 13 33 1 34 23 35 |
|||
1 36 1 37 25 38 11 39 1 40 |
|||
27 41 1 42 17 43 29 44 1 45 |
|||
13 46 31 47 19 48 1 49 33 50</pre> |
|||
==={{header|FutureBasic}}=== |
|||
<syntaxhighlight lang="futurebasic">NSUInteger i, j |
|||
print " 1 1"; |
|||
for i = 3 to 100 |
|||
for j = i - 1 to 1 step - 1 |
|||
if i mod j = 0 then print using "###"; j; : exit for |
|||
next |
|||
if i mod 10 = 0 then print |
|||
next |
|||
HandleEvents</syntaxhighlight> |
|||
{{output}} |
|||
<pre> 1 1 1 2 1 3 1 4 3 5 |
|||
1 6 1 7 5 8 1 9 1 10 |
|||
7 11 1 12 5 13 9 14 1 15 |
|||
1 16 11 17 7 18 1 19 13 20 |
|||
1 21 1 22 15 23 1 24 7 25 |
|||
17 26 1 27 11 28 19 29 1 30 |
|||
1 31 21 32 13 33 1 34 23 35 |
|||
1 36 1 37 25 38 11 39 1 40 |
|||
27 41 1 42 17 43 29 44 1 45 |
|||
13 46 31 47 19 48 1 49 33 50</pre> |
|||
==={{header|GW-BASIC}}=== |
|||
<syntaxhighlight lang="gwbasic">10 PRINT 1; |
|||
20 FOR I = 1 TO 101 |
|||
30 FOR D = I\2 TO 1 STEP -1 |
|||
40 IF I MOD D = 0 THEN PRINT D; : GOTO 60 |
|||
50 NEXT D |
|||
60 NEXT I</syntaxhighlight> |
|||
==={{header|PureBasic}}=== |
|||
<syntaxhighlight lang="purebasic">Procedure.i lpd(v.i) |
|||
For i=v/2 To 1 Step -1 |
|||
If v%i=0 : ProcedureReturn i : EndIf |
|||
Next |
|||
ProcedureReturn 1 |
|||
EndProcedure |
|||
If OpenConsole("") |
|||
For i=1 To 100 |
|||
Print(RSet(Str(lpd(i)),3)) |
|||
If i%10=0 : PrintN("") : EndIf |
|||
Next |
|||
Input() |
|||
EndIf</syntaxhighlight> |
|||
{{out}} |
|||
<pre> 1 1 1 2 1 3 1 4 3 5 |
|||
1 6 1 7 5 8 1 9 1 10 |
|||
7 11 1 12 5 13 9 14 1 15 |
|||
1 16 11 17 7 18 1 19 13 20 |
|||
1 21 1 22 15 23 1 24 7 25 |
|||
17 26 1 27 11 28 19 29 1 30 |
|||
1 31 21 32 13 33 1 34 23 35 |
|||
1 36 1 37 25 38 11 39 1 40 |
|||
27 41 1 42 17 43 29 44 1 45 |
|||
13 46 31 47 19 48 1 49 33 50</pre> |
|||
==={{header|True BASIC}}=== |
|||
{{trans|FreeBASIC}} |
|||
<syntaxhighlight lang="qbasic">PRINT "El mayor divisor propio de n es:" |
|||
PRINT |
|||
PRINT " 1 1"; |
|||
FOR i = 3 To 100 |
|||
FOR j = i-1 To 1 Step -1 |
|||
IF remainder(i, j) = 0 Then |
|||
PRINT Using$("###", j); |
|||
EXIT FOR |
|||
END IF |
|||
NEXT j |
|||
IF remainder(i, 10) = 0 Then PRINT |
|||
NEXT i |
|||
END</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as FreeBASIC entry.</pre> |
|||
==={{header|Yabasic}}=== |
|||
{{trans|FreeBASIC}} |
|||
<syntaxhighlight lang="yabasic">print "El mayor divisor propio de n es:\n" |
|||
print " 1 1 "; |
|||
for i = 3 to 100 |
|||
for j = i-1 to 1 step -1 |
|||
If mod(i, j) = 0 then print j using "##"; : break : fi |
|||
next j |
|||
if mod(i, 10) = 0 then print : fi |
|||
next i |
|||
print |
|||
end</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as FreeBASIC entry.</pre> |
|||
=={{header|BCPL}}== |
=={{header|BCPL}}== |
||
Line 936: | Line 1,051: | ||
{{out}} |
{{out}} |
||
<pre> 1 1 1 2 1 3 1 4 3 5 |
<pre> 1 1 1 2 1 3 1 4 3 5 |
||
1 6 1 7 5 8 1 9 1 10 |
|||
7 11 1 12 5 13 9 14 1 15 |
|||
1 16 11 17 7 18 1 19 13 20 |
|||
1 21 1 22 15 23 1 24 7 25 |
|||
17 26 1 27 11 28 19 29 1 30 |
|||
1 31 21 32 13 33 1 34 23 35 |
|||
1 36 1 37 25 38 11 39 1 40 |
|||
27 41 1 42 17 43 29 44 1 45 |
|||
13 46 31 47 19 48 1 49 33 50</pre> |
|||
=={{header|FreeBASIC}}== |
|||
<syntaxhighlight lang="freebasic">Print !"El mayor divisor propio de n es:\n" |
|||
Print " 1 1"; |
|||
For i As Byte = 3 To 100 |
|||
For j As Byte = i-1 To 1 Step -1 |
|||
If i Mod j = 0 Then Print Using "###"; j; : Exit For |
|||
Next j |
|||
If i Mod 10 = 0 Then Print |
|||
Next i |
|||
Sleep</syntaxhighlight> |
|||
{{out}} |
|||
<pre>El mayor divisor propio de n es: |
|||
1 1 1 2 1 3 1 4 3 5 |
|||
1 6 1 7 5 8 1 9 1 10 |
1 6 1 7 5 8 1 9 1 10 |
||
7 11 1 12 5 13 9 14 1 15 |
7 11 1 12 5 13 9 14 1 15 |
||
Line 976: | Line 1,066: | ||
<syntaxhighlight lang="frink">for n = 1 to 100 |
<syntaxhighlight lang="frink">for n = 1 to 100 |
||
println[last[allFactors[n,true,false]]]</syntaxhighlight> |
println[last[allFactors[n,true,false]]]</syntaxhighlight> |
||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
NSUInteger i, j |
|||
print " 1 1"; |
|||
for i = 3 to 100 |
|||
for j = i - 1 to 1 step - 1 |
|||
if i mod j = 0 then print using "###"; j; : exit for |
|||
next |
|||
if i mod 10 = 0 then print |
|||
next |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
<pre> |
|||
1 1 1 2 1 3 1 4 3 5 |
|||
1 6 1 7 5 8 1 9 1 10 |
|||
7 11 1 12 5 13 9 14 1 15 |
|||
1 16 11 17 7 18 1 19 13 20 |
|||
1 21 1 22 15 23 1 24 7 25 |
|||
17 26 1 27 11 28 19 29 1 30 |
|||
1 31 21 32 13 33 1 34 23 35 |
|||
1 36 1 37 25 38 11 39 1 40 |
|||
27 41 1 42 17 43 29 44 1 45 |
|||
13 46 31 47 19 48 1 49 33 50 |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 1,051: | Line 1,110: | ||
13 46 31 47 19 48 1 49 33 50 |
13 46 31 47 19 48 1 49 33 50 |
||
</pre> |
</pre> |
||
=={{header|GW-BASIC}}== |
|||
<syntaxhighlight lang="gwbasic">10 PRINT 1; |
|||
20 FOR I = 1 TO 101 |
|||
30 FOR D = I\2 TO 1 STEP -1 |
|||
40 IF I MOD D = 0 THEN PRINT D; : GOTO 60 |
|||
50 NEXT D |
|||
60 NEXT I</syntaxhighlight> |
|||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Line 1,497: | Line 1,543: | ||
CALL EXIT; |
CALL EXIT; |
||
EOF</syntaxhighlight> |
EOF</syntaxhighlight> |
||
{{out}} |
|||
<pre> 1 1 1 2 1 3 1 4 3 5 |
|||
1 6 1 7 5 8 1 9 1 10 |
|||
7 11 1 12 5 13 9 14 1 15 |
|||
1 16 11 17 7 18 1 19 13 20 |
|||
1 21 1 22 15 23 1 24 7 25 |
|||
17 26 1 27 11 28 19 29 1 30 |
|||
1 31 21 32 13 33 1 34 23 35 |
|||
1 36 1 37 25 38 11 39 1 40 |
|||
27 41 1 42 17 43 29 44 1 45 |
|||
13 46 31 47 19 48 1 49 33 50</pre> |
|||
=={{header|PureBasic}}== |
|||
<syntaxhighlight lang="purebasic">Procedure.i lpd(v.i) |
|||
For i=v/2 To 1 Step -1 |
|||
If v%i=0 : ProcedureReturn i : EndIf |
|||
Next |
|||
ProcedureReturn 1 |
|||
EndProcedure |
|||
If OpenConsole("") |
|||
For i=1 To 100 |
|||
Print(RSet(Str(lpd(i)),3)) |
|||
If i%10=0 : PrintN("") : EndIf |
|||
Next |
|||
Input() |
|||
EndIf</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre> 1 1 1 2 1 3 1 4 3 5 |
<pre> 1 1 1 2 1 3 1 4 3 5 |
||
Line 2,030: | Line 2,049: | ||
end subroutine |
end subroutine |
||
|} |
|} |
||
=={{header|True BASIC}}== |
|||
{{trans|FreeBASIC}} |
|||
<syntaxhighlight lang="qbasic">PRINT "El mayor divisor propio de n es:" |
|||
PRINT |
|||
PRINT " 1 1"; |
|||
FOR i = 3 To 100 |
|||
FOR j = i-1 To 1 Step -1 |
|||
IF remainder(i, j) = 0 Then |
|||
PRINT Using$("###", j); |
|||
EXIT FOR |
|||
END IF |
|||
NEXT j |
|||
IF remainder(i, 10) = 0 Then PRINT |
|||
NEXT i |
|||
END</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Igual que la entrada de FreeBASIC. |
|||
</pre> |
|||
=={{header|V (Vlang)}}== |
=={{header|V (Vlang)}}== |
||
Line 2,110: | Line 2,109: | ||
{{out}} |
{{out}} |
||
<pre>The largest proper divisors for numbers in the interval [1, 100] are: |
|||
<pre> |
|||
The largest proper divisors for numbers in the interval [1, 100] are: |
|||
1 1 1 2 1 3 1 4 3 5 |
1 1 1 2 1 3 1 4 3 5 |
||
1 6 1 7 5 8 1 9 1 10 |
1 6 1 7 5 8 1 9 1 10 |
||
Line 2,121: | Line 2,119: | ||
1 36 1 37 25 38 11 39 1 40 |
1 36 1 37 25 38 11 39 1 40 |
||
27 41 1 42 17 43 29 44 1 45 |
27 41 1 42 17 43 29 44 1 45 |
||
13 46 31 47 19 48 1 49 33 50 |
13 46 31 47 19 48 1 49 33 50 </pre> |
||
</pre> |
|||
=={{header|Yabasic}}== |
|||
{{trans|FreeBASIC}} |
|||
<syntaxhighlight lang="yabasic">print "El mayor divisor propio de n es:\n" |
|||
print " 1 1 "; |
|||
for i = 3 to 100 |
|||
for j = i-1 to 1 step -1 |
|||
If mod(i, j) = 0 then print j using "##"; : break : fi |
|||
next j |
|||
if mod(i, 10) = 0 then print : fi |
|||
next i |
|||
print |
|||
end</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Igual que la entrada de FreeBASIC. |
|||
</pre> |
|||
=={{header|X86 Assembly}}== |
=={{header|X86 Assembly}}== |