User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Legacy and Other Languages section within the Software Development category of DaniWeb, a massive community of 363,778 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,471 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Legacy and Other Languages advertiser:
Jan 1st, 2005
Views: 8,017
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.
qbasic Syntax | 4 stars
  1. ' look at a series of numbers and print out the prime numbers
  2. ' prime numbers are divisible only by unity or themselves
  3. ' this is BCX basic, a modern successor to Qbasic
  4.  
  5. DIM A ' defaults to integer
  6.  
  7. FOR A = 1 TO 100
  8. IF IsPrime(A) THEN PRINT A;
  9. NEXT
  10.  
  11. Pause ' make console wait
  12.  
  13. FUNCTION IsPrime(Num)
  14. LOCAL X
  15. ' make exeptions for unity and 2
  16. IF Num = 1 THEN FUNCTION = True
  17. IF Num = 2 THEN FUNCTION = True
  18. ' leave on even numbers
  19. IF MOD(Num, 2) = 0 THEN EXIT FUNCTION
  20. FOR X = 3 TO Num - 1 STEP 2
  21. IF MOD(Num, X) = 0 THEN EXIT FUNCTION
  22. NEXT X
  23. FUNCTION = TRUE ' return true if it's a Prime Number
  24. END FUNCTION
Comments (Newest First)
vegaseat | Kickbutt Moderator | Jan 9th, 2007
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 | Kickbutt Moderator | Jan 1st, 2005
Thanks, I knew you would!
cscgal | The Queen of DaniWeb | Jan 1st, 2005
Working on it
vegaseat | Kickbutt Moderator | Jan 1st, 2005
Well, indent doesn't work and highlighting is hit and miss, just like the real Qbasic code snippet.
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 10:34 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC