954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Print out Prime Numbers

0
By vegaseat on Jan 2nd, 2005 3:05 am

I just had to do this to see how it would look like in the code field. This small prime number generator is written in BCX basic, a mildy more modern basic than Qbasic. With BCX basic you can throw in C and assembler code and it would actually compile it. Gives you the familiar comfort of basic, but allows you to venture to C at will.

' look at a series of numbers and print out the prime numbers
' prime numbers are divisible only by unity or themselves
' this is BCX basic, a modern successor to Qbasic

Dim A    ' defaults to integer

For A = 1 To 100
  If IsPrime(A) Then Print A;
Next

Pause   ' make console wait

Function IsPrime(Num)
  Local X
  ' make exeptions for unity and 2
  If Num = 1 Then Function = True
  If Num = 2 Then Function = True
  ' leave on even numbers
  If Mod(Num, 2) = 0 Then Exit Function
  For X = 3 To Num - 1 Step 2
    If Mod(Num, X) = 0 Then Exit Function
  Next X
  Function = TRUE  ' return true if it's a Prime Number
End Function

Well, indent doesn't work and highlighting is hit and miss, just like the real Qbasic code snippet.

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

Working on it :)

cscgal
The Queen of DaniWeb
Administrator
19,427 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
 

Thanks, I knew you would!

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

Prime numbers are:
Any natural number greater than 1 that has the two divisors 1 and itself.

Defined in: http://en.wikipedia.org/wiki/Prime_number

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You