Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prime factors in 25 lines or less
#1
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
Reply
#2
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:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#3
Someone with one post? Smells like homework... NM my solution..edited.

I think I'll wait a day or so..
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#4
Everyone has a first post ...and I wish I were young enough to have homework! :o
Reply
#5
Well, your words, your stringent output conditions, and your spelling suggests otherwise. . . . . .

Tell us a little about your line of work..
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#6
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:
Reply
#7
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
ignatures suck
Reply
#8
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.
Reply
#9
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
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#10
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)