|
16 May 2003, 13:28
|
#1
|
Little Bitch
Join Date: Jun 2001
Location: Location Location!
Posts: 771
|
Does anyone fancy
writing me two QBasic programs for me?
I need one to work out and print all prime numbers under 1000.
And I need one that uses the Taylor series expansion to calculate exp(x)
You have 10 minutes to do it in btw.
__________________
Well I'd love to stay and talk, but you're a total bitch.
|
|
|
16 May 2003, 13:30
|
#2
|
Shai Halud
Join Date: Aug 2001
Location: Sunny Leeds \o/
Posts: 2,127
|
I have the primes one already done.
Shame it's at home though - I'll rustle up another version now.
Someone else can do the one that actually needs effort.
|
|
|
16 May 2003, 13:30
|
#3
|
Anon.
Join Date: Sep 2000
Location: not in Milton Keynes
Posts: 491
|
ok.
wait ten minutes.
|
|
|
16 May 2003, 13:30
|
#4
|
Little Bitch
Join Date: Jun 2001
Location: Location Location!
Posts: 771
|
Quote:
Originally posted by sayonara
I have the primes one already done.
Shame it's at home though - I'll rustle up another version now.
Someone else can do the one that actually needs effort.
|
Yay!
I'll need the source code though
__________________
Well I'd love to stay and talk, but you're a total bitch.
|
|
|
16 May 2003, 13:35
|
#5
|
The Twilight of the Gods
Join Date: Jan 2001
Posts: 23,481
|
The taylor expansion's easy.
10 INPUT X
20 LET Q = 1
30 LET T = 0
40 LET E = 0
50 LET P = 1 TO 1000
60 LET T = (X^P)/Q
70 LET E = E + T
80 LET Q = Q*(P+1)
90 NEXT P
100 PRINT E
does it to 1001 iterations
(ofc that's in BBC Basic, don't use QBasic personally)
|
|
|
16 May 2003, 13:37
|
#6
|
Registered User
Join Date: Jun 2000
Posts: 8,476
|
10 PRINT "JIGGLYPUFF"
20 GOTO 10
|
|
|
16 May 2003, 13:41
|
#7
|
Registered User
Join Date: Aug 2002
Location: Bromley
Posts: 806
|
<usual_reply>
DO YOUR OWN ****ING HOMEWORK
</usual_reply>
__________________
Proud to be a pr0nstar and [TiT]
Proud to have been:
[_DoG_]HC
[ICE]DC
[Deus]
[Tok'ra]
[Ostraka]
www.tit.aresexy.com
|
|
|
16 May 2003, 13:43
|
#8
|
And you expected Kittens?
Join Date: Nov 2001
Location: Purgatory, Upper Hell, Manchester.
Posts: 478
|
10 PRINT NODROG HAS CAUGHT "THE GHEY"
20 RUNPROG c:\Docs\mockinglaughter.wav
30 GOTO 10
RUN
__________________
If music be the food of love, then industrial techno be the food of BDSM.
|
|
|
16 May 2003, 13:44
|
#9
|
Little Bitch
Join Date: Jun 2001
Location: Location Location!
Posts: 771
|
It's not homework, its stuff we're doing in a 3hr practical for physics today, I've already done 3 weeks of it and bored as **** with it, plus its friday afternoon, and the quicker I get it done the quicker i can go home.
Not only this, but the people who are doing the class have no clue. And the keyboards there are crap.
__________________
Well I'd love to stay and talk, but you're a total bitch.
|
|
|
16 May 2003, 13:45
|
#10
|
Registered User
Join Date: Aug 2002
Location: Bromley
Posts: 806
|
Quote:
Originally posted by poshphil
It's not homework, its stuff we're doing in a 3hr practical for physics today, I've already done 3 weeks of it and bored as **** with it, plus its friday afternoon, and the quicker I get it done the quicker i can go home.
Not only this, but the people who are doing the class have no clue. And the keyboards there are crap.
|
i bet you even moan when having sex!
__________________
Proud to be a pr0nstar and [TiT]
Proud to have been:
[_DoG_]HC
[ICE]DC
[Deus]
[Tok'ra]
[Ostraka]
www.tit.aresexy.com
|
|
|
16 May 2003, 14:10
|
#11
|
Shai Halud
Join Date: Aug 2001
Location: Sunny Leeds \o/
Posts: 2,127
|
Code:
10 INPUT X
20 LET Q = 1
30 LET T = 0
40 LET E = 0
50 FOR p = 1 TO 1000
60 LET T = (X ^ p) / Q
70 LET E = E + T
80 LET Q = Q * (p + 1)
90
100 PRINT E
110 NEXT p
qBasic version
It overflows at the moment - I didn't check the maths, just changed it to qB form. Every second I spend doing this increases the risk that someone will discover I have done all my work for the day
[edit - the primes one is giving me hassle 'cos Ican't remember how I did it last time. Apparently qBasic does not get the idea of "if x/n <> int(x/n) then..."]
Last edited by sayonara; 16 May 2003 at 14:26.
|
|
|
16 May 2003, 15:07
|
#12
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Quote:
Originally posted by sayonara
[edit - the primes one is giving me hassle 'cos Ican't remember how I did it last time. Apparently qBasic does not get the idea of "if x/n <> int(x/n) then..."]
|
Use the mod operator, it's % in most languages.
x % n is equivalent to x/n <> int(x/n) I think. Though it could be n % x, can't remember.
__________________
You're now playing ketchup
|
|
|
16 May 2003, 15:26
|
#13
|
Shai Halud
Join Date: Aug 2001
Location: Sunny Leeds \o/
Posts: 2,127
|
x MOD n in qBasic.
Which returns an integer - huzzah!
|
|
|
16 May 2003, 15:27
|
#14
|
Henry Kelly
Join Date: Apr 2000
Posts: 7,374
|
Hmm, really has been a while since I've done 'all that jazz'.
__________________
You're now playing ketchup
|
|
|
16 May 2003, 16:03
|
#15
|
Little Bitch
Join Date: Jun 2001
Location: Location Location!
Posts: 771
|
__________________
Well I'd love to stay and talk, but you're a total bitch.
|
|
|
16 May 2003, 16:05
|
#16
|
The Twilight of the Gods
Join Date: Jan 2001
Posts: 23,481
|
Post his version of the e^x one, I want to see if it's superior.
|
|
|
16 May 2003, 16:11
|
#17
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Re: Does anyone fancy
Quote:
Originally posted by poshphil
I need one to work out and print all prime numbers under 1000.
|
PRINT "2 3 5 7 11 13 17 19 23 29 31 37 41 43 47"
PRINT "53 59 61 67 71 73 79 83 89 97 101 103 107 109 113"
PRINT "127 131 137 139 149 151 157 163 167 173 179 181 191 193 197"
PRINT "199 211 223 227 229 233 239 241 251 257 263 269 271 277 281"
PRINT "283 293 307 311 313 317 331 337 347 349 353 359 367 373 379"
PRINT "383 389 397 401 409 419 421 431 433 439 443 449 457 461 463"
PRINT "467 479 487 491 499 503 509 521 523 541 547 557 563 569 571"
PRINT "577 587 593 599 601 607 613 617 619 631 641 643 647 653 659"
PRINT "661 673 677 683 691 701 709 719 727 733 739 743 751 757 761"
PRINT "769 773 787 797 809 811 821 823 827 829 839 853 857 859 863"
PRINT "877 881 883 887 907 911 919 929 937 941 947 953 967 971 977"
PRINT "983 991 997"
|
|
|
16 May 2003, 16:21
|
#18
|
Shai Halud
Join Date: Aug 2001
Location: Sunny Leeds \o/
Posts: 2,127
|
Re: Re: Does anyone fancy
Quote:
Originally posted by queball
|
|
|
|
16 May 2003, 17:27
|
#19
|
The Twilight of the Gods
Join Date: Jan 2001
Posts: 23,481
|
Quote:
Originally posted by MrL_JaKiri
The taylor expansion's easy.
10 INPUT X
20 LET Q = 1
30 LET T = 0
40 LET E = 0
50 LET P = 1 TO 1000
60 LET T = (X^P)/Q
70 LET E = E + T
80 LET Q = Q*(P+1)
90 NEXT P
100 PRINT E
does it to 1001 iterations
(ofc that's in BBC Basic, don't use QBasic personally)
|
While I was walking in town, I realised that this is wrong
10 INPUT X
20 LET Q = 1
30 LET T = 0
40 LET E = 1
50 FOR P = 1 TO 1000
60 LET T = (X^P)/Q
70 LET E = E + T
80 LET Q = Q*(P+1)
90 NEXT P
100 PRINT E
Is the correct QBasic one.
(Let E = 1, not 0)
|
|
|
16 May 2003, 18:07
|
#20
|
Shai Halud
Join Date: Aug 2001
Location: Sunny Leeds \o/
Posts: 2,127
|
Quote:
Originally posted by MrL_JaKiri
While I was walking in town, I realised that this is wrong
(Let E = 1, not 0)
|
That would explain the overflow. Like I said, I didn't check the maths
|
|
|
16 May 2003, 18:10
|
#21
|
Clerk
Join Date: Jun 2001
Posts: 13,940
|
Isn't "LET" redundant in QBasic?
a = 1 should be the same as LET a = 1, etc.
|
|
|
16 May 2003, 18:11
|
#22
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Quote:
Originally posted by sayonara
That would explain the overflow. Like I said, I didn't check the maths
|
That's more likely to be the result of working out the factorial of 1000.
|
|
|
16 May 2003, 18:25
|
#23
|
The Twilight of the Gods
Join Date: Jan 2001
Posts: 23,481
|
Quote:
Originally posted by queball
That's more likely to be the result of working out the factorial of 1000.
|
Well, I meant 100 when I originally posted it.
The explaning line was an edit, so I claim 'error carried through'
[edit]
Perhaps 50 would be better. Or 20.
|
|
|
16 May 2003, 18:26
|
#24
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Quote:
Originally posted by MrL_JaKiri
Well, I meant 100 when I originally posted it.
The explaning line was an edit, so I claim 'error carried through'
|
9332621544394415268169923885626670049071596826438162146859296389521759999322991560894146397615651828 6253697920827223758251185210916864000000000000000000000000 is still pretty big
|
|
|
16 May 2003, 18:27
|
#25
|
The Twilight of the Gods
Join Date: Jan 2001
Posts: 23,481
|
Yeah, but if you want e^x to loads of dp...
[edit]
And he didn't say it actually had to work, just that the program was valid.
|
|
|
16 May 2003, 18:38
|
#26
|
Banned
Join Date: Oct 2000
Location: leeds
Posts: 592
|
|
|
|
16 May 2003, 19:14
|
#27
|
Little Bitch
Join Date: Jun 2001
Location: Location Location!
Posts: 771
|
Quote:
Originally posted by MrL_JaKiri
Post his version of the e^x one, I want to see if it's superior.
|
It's in the physics computer lab. Thats far too far away.
Sorry
__________________
Well I'd love to stay and talk, but you're a total bitch.
|
|
|
16 May 2003, 22:08
|
#28
|
Shai Halud
Join Date: Aug 2001
Location: Sunny Leeds \o/
Posts: 2,127
|
Quote:
Originally posted by queball
That's more likely to be the result of working out the factorial of 1000.
|
Like I said, I didn't work out the maths.
|
|
|
16 May 2003, 23:00
|
#29
|
Checkout Boy
Join Date: Jun 2002
Posts: 622
|
there should be ****ing buttons for this kind of stuff on they keyboard
__________________
David Dickinson says:
you're desperate in virtually every aspect of your life
|
|
|
17 May 2003, 00:14
|
#30
|
Gubbish
Join Date: Sep 2000
Location: #FoW
Posts: 2,323
|
Code:
const limit=1000
dim b(limit)
a=2:t=1
do while a<=sqr(limit)
for d=0 to limit step a:b(d)=b(d)+1:next d
print a
do while b(a)>0:a=a+1:loop
loop
do while a<=limit
if b(a)=0 then print a
a=a+1
loop
Has the nice side effect of resulting in an array b() of how many prime factors every number lower than the limit has.
__________________
Gubble gubble gubble gubble
|
|
|
|
All times are GMT +1. The time now is 13:31.
| |