Factors of an integer: Difference between revisions

Content added Content deleted
(Undo revision 101016 by 81.255.154.129 (previous version worked fine; no need to make it more complex))
m (alphabetized list; changed realbasic lang tag to vb)
Line 1,116: Line 1,116:
[1] 1 2 4 8 16 32 64
[1] 1 2 4 8 16 32 64
</lang>
</lang>

=={{header|REALbasic}}==
<lang vb>Function factors(num As UInt64) As UInt64()
'This function accepts an unsigned 64 bit integer as input and returns an array of unsigned 64 bit integers
Dim result() As UInt64
Dim iFactor As UInt64 = 1
While iFactor <= num/2 'Since a factor will never be larger than half of the number
If num Mod iFactor = 0 Then
result.Append(iFactor)
End If
iFactor = iFactor + 1
Wend
iFactor.Append(num) 'Since a given number is always a factor of itself
Return result
End Function</lang>


=={{header|REXX}}==
=={{header|REXX}}==
Line 1,362: Line 1,377:
n= 200 divisors=1 2 4 5 8 10 20 25 40 50 100 200
n= 200 divisors=1 2 4 5 8 10 20 25 40 50 100 200
</pre>
</pre>
=={{header|REALbasic}}==
<lang realbasic>
Function factors(num As UInt64) As UInt64()
//This function accepts an unsigned 64 bit integer as input and returns an array of unsigned 64 bit integers
Dim result() As UInt64
Dim iFactor As UInt64 = 1
While iFactor <= num/2 //Since a factor will never be larger than half of the number
If num Mod iFactor = 0 Then
result.Append(iFactor)
End If
iFactor = iFactor + 1
Wend
iFactor.Append(num) //Since a given number is always a factor of itself
Return result
End Function
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
Line 1,402: Line 1,401:
[1, 53]
[1, 53]
[1, 2, 4, 8, 16, 32, 64]</pre>
[1, 2, 4, 8, 16, 32, 64]</pre>

=={{header|Sather}}==
=={{header|Sather}}==
{{trans|C++}}
{{trans|C++}}
Line 1,452: Line 1,452:
Output:
Output:
(1 239 4649 1111111)
(1 239 4649 1111111)

=={{header|Slate}}==
=={{header|Slate}}==
<lang slate>
<lang slate>