45 lines
1.0 KiB
Plaintext
45 lines
1.0 KiB
Plaintext
// library: math: get: series: fibonacci <description></description> <version control></version control> <version>1.0.0.0.3</version> <version control></version control> (filenamemacro=getmasfi.s) [<Program>] [<Research>] [kn, ri, su, 20-01-2013 22:04:02]
|
|
INTEGER PROC FNMathGetSeriesFibonacciI( INTEGER nI )
|
|
//
|
|
// Method:
|
|
//
|
|
// 1. Take the sum of the last 2 terms
|
|
//
|
|
// 2. Let the sum be the last term
|
|
// and goto step 1
|
|
//
|
|
INTEGER I = 0
|
|
INTEGER minI = 1
|
|
INTEGER maxI = nI
|
|
INTEGER term1I = 0
|
|
INTEGER term2I = 1
|
|
INTEGER term3I = 0
|
|
//
|
|
FOR I = minI TO maxI
|
|
//
|
|
// make value 3 equal to sum of two previous values 1 and 2
|
|
//
|
|
term3I = term1I + term2I
|
|
//
|
|
// make value 1 equal to next value 2
|
|
//
|
|
term1I = term2I
|
|
//
|
|
// make value 2 equal to next value 3
|
|
//
|
|
term2I = term3I
|
|
//
|
|
ENDFOR
|
|
//
|
|
RETURN( term3I )
|
|
//
|
|
END
|
|
|
|
PROC Main()
|
|
STRING s1[255] = "3"
|
|
REPEAT
|
|
IF ( NOT ( Ask( " = ", s1, _EDIT_HISTORY_ ) ) AND ( Length( s1 ) > 0 ) ) RETURN() ENDIF
|
|
Warn( FNMathGetSeriesFibonacciI( Val( s1 ) ) ) // gives e.g. 3
|
|
UNTIL FALSE
|
|
END
|