Jump to content

Count in factors: Difference between revisions

Added FreeBASIC
(Added FreeBASIC)
Line 1,232:
end program count_in_factors
</lang>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
Sub getPrimeFactors(factors() As UInteger, n As UInteger)
If n < 2 Then Return
Dim factor As UInteger = 2
Do
If n Mod factor = 0 Then
Redim Preserve factors(0 To UBound(factors) + 1)
factors(UBound(factors)) = factor
n \= factor
If n = 1 Then Return
Else
factor += 1
End If
Loop
End Sub
 
Dim factors() As UInteger
 
For i As UInteger = 1 To 20
Print Using "##"; i;
Print " = ";
If i > 1 Then
Erase factors
getPrimeFactors factors(), i
For j As Integer = LBound(factors) To UBound(factors)
Print factors(j);
If j < UBound(factors) Then Print " x ";
Next j
Print
Else
Print i
End If
Next i
 
Print
Print "Press any key to quit"
Sleep</lang>
 
{{out}}
<pre>
1 = 1
2 = 2
3 = 3
4 = 2 x 2
5 = 5
6 = 2 x 3
7 = 7
8 = 2 x 2 x 2
9 = 3 x 3
10 = 2 x 5
11 = 11
12 = 2 x 2 x 3
13 = 13
14 = 2 x 7
15 = 3 x 5
16 = 2 x 2 x 2 x 2
17 = 17
18 = 2 x 3 x 3
19 = 19
20 = 2 x 2 x 5
</pre>
 
=={{header|Go}}==
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.