continued fractions
Thank you all.
I solved my time problem using another anti-virus-program.
Why are you so upset because used "goto". This is obviously possible and yields a correct result. "exit for" and "exit return" do here the same.
Kind regards
Volker
Announcement
Collapse
No announcement yet.
continued fractions
Collapse
X
-
>Could have replaced gosub with goto, but goto starts arguements
Hmm, that happens in COBOL newsgroups, too, when code using GO TO is posted.
But nearly as big an argument as you can provoke by suggesting various uses of the full stop (the period, ".").
Thank goodness the comma (",") in COBOL is always optional and always 'documentary only!'
Leave a comment:
-
Code:#compile exe #dim all function solution(x as double,arr() as long)as long dim k as long, a as long dim y as double for k = 0 to 17 a = int(x) arr(k) = a y = x - a if y = 0 then exit function else x = 1/y end if next k end function function pbmain () as long dim arr(18) as long dim i as long local T_Start, T_Stop as double T_Start = timer solution(sqr(7),arr()) for i = 0 to 17 print str$(arr(i))+" "; next i 'sleep 100 'keep coming up 0 seconds on my PC 'temporarily added sleep to check my code T_Stop = timer print : print str$(T_Stop - T_Start) waitkey$ end function
Also fixed the gosub without return. Could have replaced gosub with goto, but goto starts arguements.
Cheers,
Leave a comment:
-
Originally posted by Michael Mattias View Post...totally and absolutely unforgiveable, especially when dealing with a 'newbie,' and super-especially coming from someone who has been writing in BASIC as long as have you.
Leave a comment:
-
Originally posted by Paul Dixon View Post...code is taking 23 seconds...there is a big problem...
Leave a comment:
-
> In the context given, the GOSUB does not appear to add any value at all.
It's clearly the wrong choice - in context.
However, not coding a RETURN when you code a GOSUB is totally and absolutely unforgiveable, especially when dealing with a 'newbie,' and super-especially coming from someone who has been writing in BASIC as long as have you.
Assuming the compiler is always going to be your momma and clean up after you is a very, very, very bad habit to acquire.
Leave a comment:
-
Volker,
are you sure you have posted the correct code?
The answer I get is:
2 1 1 1 4 1 1 1 4 1 1 1 4 1 1 1 4 1
If the same code is taking 23 seconds for you then there is a big problem somewhere.
Paul.
Leave a comment:
-
Re: continued fractions
I am very sorry but my time is over 23 seconds. I would not have bothered you otherwise. Maybe it' s Vista !
kind regards
Volker
Leave a comment:
-
GOSUB should NEVER be used without a paired RETURN.
In the context given, the GOSUB does not appear to add any value at all.
Leave a comment:
-
>your program runs in under 2 microseconds.
I was afraid to try it myself, for fear I would become far less diplomatic than "How fast do you want it?"
BTW, the "exit function" thing? That should be a command, not a suggestion. GOSUB should NEVER be used without a paired RETURN.
MCM
Leave a comment:
-
Volker,
your program runs in under 2 microseconds. How fast do you want it?
Some suggestions:
Change:
DIM y AS DOUBLE
to
REGISTER y AS EXT
Don't use
GOSUB endit
instead use
EXIT FUNCTION
Paul.
Leave a comment:
-
continued fractions
Hi,
I am looking for help again. Here is my code:
#COMPILE EXE
#DIM ALL
FUNCTION PBMAIN () AS LONG
DIM arr(18) AS LONG
DIM i AS LONG
solution(SQR(7),arr())
FOR i = 0 TO 17
PRINT STR$(arr(i))+" ";
NEXT i
WAITKEY$
END FUNCTION
FUNCTION solution(x AS DOUBLE,arr() AS LONG)AS LONG
DIM k AS LONG, a AS LONG
DIM y AS DOUBLE
FOR k = 0 TO 17
a = INT(x)
arr(k) = a
y = x - a
IF y = 0 THEN
GOSUB endit
ELSE
x = 1/y
END IF
NEXT k
endit:
END FUNCTION
The result is correct but the time is not! Has anyone an idea to make it faster?
kind regards
VolkerTags: None
Leave a comment: