# Qbasicnews.com

Full Version: Prime factors in 25 lines or less
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
In 25 lines or less, write a program in QBasic that lists the prime factors of any positive integer. The program prompts the user for a number, then prints to the screen: "The prime factors are:", and then lists them. If the entered number is already prime, it will be the only number listed. The number 1 is not considered prime.
Statements separated by colons are considered separate lines.

For checking purposes, if you enter 987654321, the list should read: 3,3,17,17,379721
You might want to have a no : rule,. other wise someone could do it in one line.... At least with FBIde or NotePad,. I think QB's IDE had a 260 cross limit or something... :wink:

Edit: Oops, sorry, you did, I missed that line... :oops:
Someone with one post? Smells like homework... NM my solution..edited.

I think I'll wait a day or so..
Everyone has a first post ...and I wish I were young enough to have homework! :o
Well, your words, your stringent output conditions, and your spelling suggests otherwise. . . . . .

My words, my spelling...Ah!, I see. You're one of those arrogant nerds who hides behind a computer monitor and snipes at others. I think that my best course is to ignore your words. :barf:
Code:
```INPUT "enter a number: ", x& PRINT "the prime factors are:"; k& = 2 WHILE k& <= x&   WHILE x& MOD k& = 0     x& = x& / k&     PRINT k&;   WEND   k& = k& + 1 WEND PRINT```

- neuro
Quote:My words, my spelling...Ah!, I see. You're one of those arrogant nerds who hides behind a computer monitor and snipes at others. I think that my best course is to ignore your words. :barf:
...
Agamemnus is just making an observation about your language and you should give a little more respect to him. I had a chance to get to know him a few years ago and he turned out to be a pretty nice (and helpful) guy.
That wasn't very nice.

Did I call you an arrogant noob?

No...

Anyway, I posted mine in the FAQ, so I guess I'll post it again since neuro volunteered his code..

Code:
```CLS DIM testfactor&(1 TO 100) DIM isfactored%(1 TO 100) n% = 1 newfree% = 1 INPUT "What is the number you want to factor"; testfactor&(n%) DO if testfactor%(n%) = 0 THEN EXIT DO FOR testdiv& = 2 TO testfactor%(n%) ^ .5 'There is a more efficient way to do \ and /, but I don't remember it. result1& = testfactor&(n%) \ testdiv& IF result1& = testfactor&(n%) / testdiv& THEN isfactored%(n%) = 1 testfactor&(newfree% + 1) = result1& testfactor&(newfree% + 2) = testdiv& newfree% = newfree% + 2 EXIT FOR END IF NEXT testdiv& n% = n% + 1 LOOP FOR i% = 1 TO newfree% IF isfactored%(i%) = 0 THEN PRINT testfactor&(i%) next i% SLEEP```
Quote:
whodat Wrote:My words, my spelling...Ah!, I see. You're one of those arrogant nerds who hides behind a computer monitor and snipes at others. I think that my best course is to ignore your words. :barf:
...
Agamemnus is just making an observation about your language and you should give a little more respect to him. I had a chance to get to know him a few years ago and he turned out to be a pretty nice (and helpful) guy.

Ok, he's a nice guy. He just had a rather peculiar way of introducing himself.
Pages: 1 2 3