QB64 Phoenix Edition
Welcome to 2023. - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Welcome to 2023. (/showthread.php?tid=1453)



Welcome to 2023. - eoredson - 02-08-2023

Hi,

Happy belated 2023! This is a program to display the factors of 2023:

Code: (Select All)
Year = 2023
z = Year - 1
Do Until z = Year
  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
End



RE: Welcome to 2023. - PhilOfPerth - 02-08-2023

An interesting program!
I wish I knew how it works though - it's quite cryptic to me!
Any chance of naming some variables, to enlighten dummies like me? 
And do the labels "80" and "0" have a purpose?


RE: Welcome to 2023. - eoredson - 02-08-2023

Actually the 80 serves no purpose. (removed)

The Year could be set to anything.

Erik.

(vote my reputation)


RE: Welcome to 2023. - PhilOfPerth - 02-08-2023

(02-08-2023, 05:40 AM)eoredson Wrote: Actually the 80 serves no purpose. (removed)

The Year could be set to anything.

Erik.

(vote my reputation)

Voted!
I tried a variety of years, and all worked correctly (except zero, negative and fractions, which I didn't really expect to work anyway). Good job!


RE: Welcome to 2023. - bplus - 02-08-2023

(02-08-2023, 05:31 AM)PhilOfPerth Wrote: An interesting program!
I wish I knew how it works though - it's quite cryptic to me!
Any chance of naming some variables, to enlighten dummies like me? 
And do the labels "80" and "0" have a purpose?

For @PhilOfPerth
Code: (Select All)
'yearInteger/testInteger = yearInteger\testInteger is one way to see if yearInteger is divided by testInteger

' / is for float return a number that might have decimals
' \ is for an Integer return a number without decimals
' When the two divisions return exactly same number the bottom number divides the top exactly.

Dim As Long testInteger, yearInteger

yearInteger = 2023
For testInteger = 2 To Sqr(yearInteger) ' <<< primes of a Number will be less than or = to Square Root of Number
    If yearInteger / testInteger = yearInteger \ testInteger Then Print testInteger; "divides"; yearInteger; yearInteger / testInteger; "times."
Next



RE: Welcome to 2023. - PhilOfPerth - 02-08-2023

Thanks bplus. Now I (sort of) get it... I'll work through it now and see if I can absorb it..
and thanks for the tag! Smile

Late extra: I got it!