Posts: 31
Threads: 4
Joined: Oct 2005
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
Posts: 2,404
Threads: 153
Joined: Jan 2005
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)
Posts: 3,368
Threads: 195
Joined: Jan 2003
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.
Posts: 31
Threads: 4
Joined: Oct 2005
Everyone has a first post ...and I wish I were young enough to have homework! :o
Posts: 3,368
Threads: 195
Joined: Jan 2003
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.
Posts: 31
Threads: 4
Joined: Oct 2005
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:
Posts: 58
Threads: 6
Joined: Feb 2005
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
Posts: 843
Threads: 60
Joined: Mar 2003
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.
Posts: 3,368
Threads: 195
Joined: Jan 2003
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.
Posts: 31
Threads: 4
Joined: Oct 2005
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.