Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prime Numbers from 2 to 50,021.
#1
B+ mentioned prime numbers in my "Make Shapes" thread so I decided to see how I could make a long list of them. I tried a few times on my own but I couldn't figure it out so I found code on a QBasic page on Google. I added the URL in the code. Their page only lets people type a number to see if it's a Prime Number or not so I just listed them with the same code pretty much and added a bit of my own. When it almost fills up a page, it asks if you want to see more which you can do so by pressing the Space Bar, or Esc to quit. It ends at 50,021. I noticed my computer slows down a little bit in the 40,000 range. Am not sure why it does that since I dimmed the number as a double and put the _LIMIT at 3000. Anyway, enjoy the numbers. Smile 

Code: (Select All)
'Prime Numbers up to 50,021.
'Thank you to: https://seeqbasicomputer.blogspot.com/2016/10/check-prime-or-composite-number-qbasic.html
Dim n As Double
Screen _NewImage(800, 600, 32)
_Title "Prime Numbers from 2 to 50,021."
Do
    _Limit 3000
    n = n + 1
    c = 0
    For I = 1 To n
        If n Mod I = 0 Then c = c + 1 'If there's no remainder from n / I, c = c + 1.
    Next I
    If c = 2 Then Print n; "  "; 'If there's no more than n / 1 and n / n then it's a prime number.
    If n > 50021 Then
        Print
        Print "Limit Finished."
        End
    End If
    If n / 3000 = Int(n / 3000) Then
        Print
        Print "Press Space Bar for more or Esc to finish."
        Do
            a$ = InKey$
            If a$ = " " Then Cls: GoTo more:
            If a$ = Chr$(27) Then End
        Loop
    End If
    more:
Loop
Reply


Messages In This Thread
Prime Numbers from 2 to 50,021. - by SierraKen - 07-13-2022, 09:48 PM



Users browsing this thread: 2 Guest(s)