Menno
Joined: 16 Jul 2014 Posts: 4
|
Posted: Thu Jul 17, 2014 1:10 pm Post subject: clearwin.pdf FUNCTION factoriser() |
|
|
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
|
|