forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

clearwin.pdf FUNCTION factoriser()

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
Menno



Joined: 16 Jul 2014
Posts: 4

PostPosted: Thu Jul 17, 2014 1:10 pm    Post subject: clearwin.pdf FUNCTION factoriser() Reply with quote

ClearWin+ Fortran Edition chapter 3 gives instruction in making windows around a function to factorise an integer.
Step 6 gives the fortran function factoriser(). The source text of this function did not compile in my program. The label 1 instruction had no place to go. So I had to improve the do loop.
Then when the program did run it was not able to factorise INTEGER MAX,
214783647. Something went out of bounds. Therefor I implemeted that k needn't to exceed sqrt(n). Look for the function below.

INTEGER FUNCTION factoriser()
INTEGER number,n,k
REAL r
CHARACTER*50 str, val
COMMON number, str
WRITE(val, '(i11)')number
CALL trim@(val)
str=val(1:LENG(val))//' is: 1'
n=number
DO k=2, n
r=SQRT(REAL(n))
IF (k>r) THEN
WRITE(val, '(i11)') n
CALL trim@(val)
CALL append_string@(str, 'x'//val)
CALL window_update@(str)
EXIT
ELSE
DO
IF ((n/k)*k < n) EXIT
WRITE(val, '(i11)') k
CALL trim@(val)
CALL append_string@(str, 'x'//val)
CALL window_update@(str)
n=n/k
END DO
ENDIF
END DO
factoriser=1
END

Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group