Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prime Factors
#8
I wrote a factorialization function here:

Code: (Select All)
Print "Enter range";
Input p: p = Int(p)
If p <= 1 Then End
z = 2
Print " 2= (prime)" ' first prime is 2
Do Until z = p ' display factored numbers
  x$ = InKey$
  If x$ = Chr$(27) Then
      End
  End If
  z = z + 1
  x = z
  Print x; "=";
  l = 1
  q = 0
  Do Until x = 1
      l = l + 1
      Do While x / l = x \ l ' continue to divide number
        q = q + 1
        If q > 1 Then
            Print "*";
        End If
        Print l;
        x = x / l
      Loop
      If l > Int(z / 2) Then ' test for maximum divisor
        Exit Do
      End If
      If l > Int(Sqr(x)) Then ' test maximum divisor is prime
        If q = 0 Then
            Exit Do
        End If
      End If
  Loop
  If q = 0 Then ' display number is prime
      Print " (prime)";
  End If
  Print
Loop


Attached Files
.zip   PRIME2.ZIP (Size: 5 KB / Downloads: 10)
Reply


Messages In This Thread
Prime Factors - by SMcNeill - 05-18-2024, 03:32 AM
RE: Prime Factors - by PhilOfPerth - 05-18-2024, 03:59 AM
RE: Prime Factors - by Jack - 09-21-2024, 10:39 PM
RE: Prime Factors - by Pete - 09-21-2024, 11:15 PM
RE: Prime Factors - by Jack - 09-22-2024, 12:00 AM
RE: Prime Factors - by SMcNeill - 09-22-2024, 12:30 AM
RE: Prime Factors - by Jack - 09-22-2024, 12:46 AM
RE: Prime Factors - by eoredson - 09-30-2024, 04:36 AM
RE: Prime Factors - by Jack - 09-30-2024, 10:59 AM
RE: Prime Factors - by SMcNeill - 09-30-2024, 12:03 PM
RE: Prime Factors - by Jack - 09-30-2024, 12:15 PM
RE: Prime Factors - by Jack - 09-30-2024, 08:42 PM
RE: Prime Factors - by SMcNeill - 09-30-2024, 11:44 PM
RE: Prime Factors - by Jack - 10-01-2024, 01:07 AM
RE: Prime Factors - by eoredson - 10-02-2024, 05:05 AM
RE: Prime Factors - by SMcNeill - 10-02-2024, 06:07 AM



Users browsing this thread: 6 Guest(s)