Factors of an integer: Difference between revisions

Content added Content deleted
(Added Gambas and XBasic)
m (Reordering BASIC dialects)
Line 1,064: Line 1,064:
==={{header|ASIC}}===
==={{header|ASIC}}===
{{trans|GW-BASIC}}
{{trans|GW-BASIC}}
<syntaxhighlight lang="basic">
<syntaxhighlight lang="basic">REM Factors of an integer
REM Factors of an integer
PRINT "Enter an integer";
PRINT "Enter an integer";
LOOP:
LOOP:
Line 1,081: Line 1,080:
END</syntaxhighlight>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>Enter an integer?60
1 2 3 4 5 6 10 12 15 20 30 60</pre>
Enter an integer?60
1 2 3 4 5 6 10 12 15 20 30 60

</pre>


==={{header|BASIC256}}===
==={{header|BASIC256}}===
Line 1,104: Line 1,100:
call printFactors(67)
call printFactors(67)
call printFactors(96)
call printFactors(96)
end</syntaxhighlight>
end
</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>


==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
Line 1,138: Line 1,129:
NEXT
NEXT
= LEFT$(LEFT$(L$))</syntaxhighlight>
= LEFT$(LEFT$(L$))</syntaxhighlight>

{{out}}
{{out}}
<pre>The factors of 45 are 1, 3, 5, 9, 15, 45
<pre>The factors of 45 are 1, 3, 5, 9, 15, 45
The factors of 12345 are 1, 3, 5, 15, 823, 2469, 4115, 12345</pre>
The factors of 12345 are 1, 3, 5, 15, 823, 2469, 4115, 12345</pre>

==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{trans|BASIC256}}
<syntaxhighlight lang="qbasic">10 cls
20 printfactors(11)
30 printfactors(21)
40 printfactors(32)
50 printfactors(45)
60 printfactors(67)
70 printfactors(96)
80 end
100 sub printfactors(n)
110 if n < 1 then printfactors = 0
120 print n "=> ";
130 for i = 1 to n/2
140 if n mod i = 0 then print i " ";
150 next i
160 print n
170 end sub</syntaxhighlight>


==={{header|Craft Basic}}===
==={{header|Craft Basic}}===
Line 1,196: Line 1,206:
96 => 1 2 3 4 6 8 12 16 24 32 48 96
96 => 1 2 3 4 6 8 12 16 24 32 48 96
</pre>
</pre>

==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
printFactors(11)
printFactors(21)
printFactors(32)
printFactors(45)
printFactors(67)
printFactors(96)

End

Sub printFactors(n As Integer)

If n < 1 Then Return
Print n; " =>";
For i As Integer = 1 To n / 2
If n Mod i = 0 Then Print i; " ";
Next
Print n

End Sub</syntaxhighlight>

==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{trans|BASIC256}}
<syntaxhighlight lang="qbasic">10 cls
20 printfactors(11)
30 printfactors(21)
40 printfactors(32)
50 printfactors(45)
60 printfactors(67)
70 printfactors(96)
80 end
100 sub printfactors(n)
110 if n < 1 then printfactors = 0
120 print n "=> ";
130 for i = 1 to n/2
140 if n mod i = 0 then print i " ";
150 next i
160 print n
170 end sub</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>


==={{header|FutureBasic}}===
==={{header|FutureBasic}}===
Line 1,294: Line 1,258:


HandleEvents</syntaxhighlight>
HandleEvents</syntaxhighlight>
{{out}}

<pre>Factors of 25 are: 1, 5, 25
Output:
<pre>
Factors of 25 are: 1, 5, 25
Factors of 45 are: 1, 3, 5, 9, 15, 45
Factors of 45 are: 1, 3, 5, 9, 15, 45
Factors of 103 are: 1, 103
Factors of 103 are: 1, 103
Line 1,306: Line 1,268:
Factors of 57097 are: 1, 57097
Factors of 57097 are: 1, 57097
Factors of 12345678 are: 1, 2, 3, 6, 9, 18, 47, 94, 141, 282, 423, 846, 14593, 29186, 43779, 87558, 131337, 262674, 685871, 1371742, 2057613, 4115226, 6172839, 12345678
Factors of 12345678 are: 1, 2, 3, 6, 9, 18, 47, 94, 141, 282, 423, 846, 14593, 29186, 43779, 87558, 131337, 262674, 685871, 1371742, 2057613, 4115226, 6172839, 12345678
Factors of 32434243 are: 1, 307, 105649, 32434243
Factors of 32434243 are: 1, 307, 105649, 32434243</pre>

</pre>
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
printFactors(11)
printFactors(21)
printFactors(32)
printFactors(45)
printFactors(67)
printFactors(96)

End

Sub printFactors(n As Integer)

If n < 1 Then Return
Print n; " =>";
For i As Integer = 1 To n / 2
If n Mod i = 0 Then Print i; " ";
Next
Print n

End Sub</syntaxhighlight>


==={{header|GW-BASIC}}===
==={{header|GW-BASIC}}===
<syntaxhighlight lang="gwbasic">
<syntaxhighlight lang="qbasic">
10 INPUT "Enter an integer: ", N
10 INPUT "Enter an integer: ", N
20 IF N = 0 THEN GOTO 10
20 IF N = 0 THEN GOTO 10
Line 1,331: Line 1,316:


==={{header|IS-BASIC}}===
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "Factors.bas"
<syntaxhighlight lang="qbasic">100 PROGRAM "Factors.bas"
110 INPUT PROMPT "Number: ":N
110 INPUT PROMPT "Number: ":N
120 FOR I=1 TO INT(N/2)
120 FOR I=1 TO INT(N/2)
Line 1,409: Line 1,394:
end function</syntaxhighlight>
end function</syntaxhighlight>
{{out}}
{{out}}

<syntaxhighlight lang="lb">Start finding all factors of 10677106534462215678539721403561279:
<syntaxhighlight lang="lb">Start finding all factors of 10677106534462215678539721403561279:
10677106534462215678539721403561279 = 29269^1 * 32579^1 * 98731^2 * 104729^3
10677106534462215678539721403561279 = 29269^1 * 32579^1 * 98731^2 * 104729^3
Line 1,531: Line 1,517:
{{works with|MSX BASIC|any}}
{{works with|MSX BASIC|any}}
{{works with|Nascom ROM BASIC|4.7}}
{{works with|Nascom ROM BASIC|4.7}}
<syntaxhighlight lang="gwbasic">10 REM Factors of an integer
<syntaxhighlight lang="qbasic">10 REM Factors of an integer
20 PRINT "Enter an integer";
20 PRINT "Enter an integer";
30 INPUT N
30 INPUT N
Line 1,546: Line 1,532:
{{trans|GW-BASIC}}
{{trans|GW-BASIC}}
<syntaxhighlight lang="qbasic">10 INPUT "Enter an integer: "; N
<syntaxhighlight lang="qbasic">10 INPUT "Enter an integer: "; N
20 IF N = 0 THEN GOTO 15
20 IF N = 0 THEN GOTO 10
30 N1 = ABS(N)
30 N1 = ABS(N)
40 FOR I = 1 TO N1/2
40 FOR I = 1 TO N1/2
50 IF N1 MOD I = 0 THEN PRINT I;
50 IF N1 MOD I = 0 THEN PRINT I;
60 NEXT I
70 PRINT N1</syntaxhighlight>

==={{header|Quite BASIC}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="qbasic">10 INPUT "Enter an integer: "; N
20 IF N = 0 THEN GOTO 15
30 N1 = ABS(N)
40 FOR I = 1 TO N1/2
50 IF N1 - INT(N1 / I) * I = 0 THEN PRINT I; " ";
60 NEXT I
60 NEXT I
70 PRINT N1</syntaxhighlight>
70 PRINT N1</syntaxhighlight>
Line 1,578: Line 1,554:
</syntaxhighlight>
</syntaxhighlight>
{{out}}
{{out}}
<pre>Enter an integer? 60
<pre>
1 2 3 4 5 6 10 12 15 20 30 60</pre>
Enter an integer? 60
1 2 3 4 5 6 10 12 15 20 30 60
</pre>
See also [[#Minimal BASIC|Minimal BASIC]]
See also [[#Minimal BASIC|Minimal BASIC]]


Line 1,600: Line 1,574:
{{out}}
{{out}}
3 runs.
3 runs.
<pre>
<pre>ENTER AN INTEGER:1
1</pre>
ENTER AN INTEGER:1
<pre>ENTER AN INTEGER:60
1
1 2 3 4 5 6 10 12 15 20 30 60</pre>
</pre>
<pre>ENTER AN INTEGER:-22222
<pre>
1 2 41 82 271 542 11111 22222</pre>
ENTER AN INTEGER:60
1 2 3 4 5 6 10 12 15 20 30 60
</pre>
<pre>
ENTER AN INTEGER:-22222
1 2 41 82 271 542 11111 22222
</pre>


==={{header|PureBasic}}===
==={{header|PureBasic}}===
Line 1,636: Line 1,604:
EndIf</syntaxhighlight>
EndIf</syntaxhighlight>
{{out}}
{{out}}
<pre> Enter integer to factorize: 96
<pre>
1 2 3 4 6 8 12 16 24 32 48 96</pre>
Enter integer to factorize: 96
1 2 3 4 6 8 12 16 24 32 48 96
</pre>


==={{header|QB64}}===
==={{header|QB64}}===
<syntaxhighlight lang="qb64">
<syntaxhighlight lang="qb64">'Task
'Task
'Compute the factors of a positive integer.
'Compute the factors of a positive integer.


Line 1,657: Line 1,622:
Index = Index - 1
Index = Index - 1
Wend
Wend
End</syntaxhighlight>
End
</syntaxhighlight>


==={{header|QBasic}}===
==={{header|QBasic}}===
Line 1,709: Line 1,673:
NEXT
NEXT
END SUB</syntaxhighlight>
END SUB</syntaxhighlight>

{{out}}
{{out}}
<pre>
<pre> Gimme a number? 17
Gimme a number? 17
1 , 17
1 , 17
Gimme a number? 12345
Gimme a number? 12345
Line 1,720: Line 1,682:
Gimme a number? 32766
Gimme a number? 32766
1 , 2 , 3 , 6 , 43 , 86 , 127 , 129 , 254 , 258 , 381 , 762 , 5461 , 10922 ,
1 , 2 , 3 , 6 , 43 , 86 , 127 , 129 , 254 , 258 , 381 , 762 , 5461 , 10922 ,
16383 , 32766
16383 , 32766</pre>

</pre>
==={{header|Quite BASIC}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="qbasic">10 INPUT "Enter an integer: "; N
20 IF N = 0 THEN GOTO 15
30 N1 = ABS(N)
40 FOR I = 1 TO N1/2
50 IF N1 - INT(N1 / I) * I = 0 THEN PRINT I; " ";
60 NEXT I
70 PRINT N1</syntaxhighlight>


==={{header|REALbasic}}===
==={{header|REALbasic}}===
Line 1,739: Line 1,710:


==={{header|Run BASIC}}===
==={{header|Run BASIC}}===
<syntaxhighlight lang="runbasic">PRINT "Factors of 45 are ";factorlist$(45)
<syntaxhighlight lang="basic">PRINT "Factors of 45 are ";factorlist$(45)
PRINT "Factors of 12345 are "; factorlist$(12345)
PRINT "Factors of 12345 are "; factorlist$(12345)
END
END
function factorlist$(f)
FUNCTION factorlist$(f)
DIM L(100)
DIM L(100)
FOR i = 1 TO SQR(f)
FOR i = 1 TO SQR(f)
Line 1,756: Line 1,727:
NEXT i
NEXT i
s = 1
s = 1
while s = 1
WHILE s = 1
s = 0
s = 0
for i = 0 to c-1
FOR i = 0 TO c-1
if L(i) > L(i+1) and L(i+1) <> 0 then
IF L(i) > L(i+1) AND L(i+1) <> 0 THEN
t = L(i)
t = L(i)
L(i) = L(i+1)
L(i) = L(i+1)
L(i+1) = t
L(i+1) = t
s = 1
s = 1
end if
END IF
next i
NEXT i
WEND
wend
FOR i = 0 TO c-1
FOR i = 0 TO c-1
factorlist$ = factorlist$ + STR$(L(i)) + ", "
factorlist$ = factorlist$ + STR$(L(i)) + ", "
NEXT
NEXT
end function</syntaxhighlight>
END FUNCTION</syntaxhighlight>
{{out}}
{{out}}
<pre>Factors of 45 are 1, 3, 5, 9, 15, 45,
<pre>Factors of 45 are 1, 3, 5, 9, 15, 45,
Line 1,811: Line 1,782:
20
20
30
30
60
60</pre>
</pre>


==={{header|True BASIC}}===
==={{header|True BASIC}}===
{{trans|FreeBASIC}}
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">
<syntaxhighlight lang="qbasic">SUB printfactors(n)
IF n < 1 THEN EXIT SUB
sub printfactors(n)
if n < 1 then exit sub
PRINT n; "=>";
print n; "=>";
FOR i = 1 TO n / 2
for i = 1 to n / 2
IF REMAINDER(n, i) = 0 THEN PRINT i;
NEXT i
if remainder(n, i) = 0 then print i;
next i
PRINT n
END SUB
print n
end sub


call printfactors(11)
CALL printfactors(11)
call printfactors(21)
CALL printfactors(21)
call printfactors(32)
CALL printfactors(32)
call printfactors(45)
CALL printfactors(45)
call printfactors(67)
CALL printfactors(67)
call printfactors(96)
CALL printfactors(96)
END</syntaxhighlight>
print
end
</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>


==={{header|VBA}}===
==={{header|VBA}}===
Line 1,888: Line 1,851:
==={{header|Yabasic}}===
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">
<syntaxhighlight lang="yabasic">sub printFactors(n)
if n < 1 return 0
sub printFactors(n)
if n < 1 then return 0 : fi
print n, " =>";
print n, " =>",
for i = 1 to n / 2
for i = 1 to n / 2
if mod(n, i) = 0 then print i, " "; : fi
if mod(n, i) = 0 print i, " ";
next i
next i
print n
print n
Line 1,905: Line 1,867:
printFactors(96)
printFactors(96)
print
print
end</syntaxhighlight>
end
</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>


==={{header|ZX Spectrum Basic}}===
==={{header|ZX Spectrum Basic}}===
{{trans|AWK}}
{{trans|AWK}}
<syntaxhighlight lang="zxbasic">10 INPUT "Enter a number or 0 to exit: ";n
<syntaxhighlight lang="basic">10 INPUT "Enter a number or 0 to exit: ";n
20 IF n=0 THEN STOP
20 IF n=0 THEN STOP
30 PRINT "Factors of ";n;": ";
30 PRINT "Factors of ";n;": ";