17 lines
426 B
Text
17 lines
426 B
Text
include "NSLog.incl"
|
|
|
|
local fn SylvesterSequence( terms as int )
|
|
NSLog( @"First %d terms of the Sylvester's sequence:", terms )
|
|
double sum = 0
|
|
long sylv
|
|
for int i = 1 to terms
|
|
if ( i == 1 ) then sylv = 2 else sylv = sylv * sylv - sylv + 1
|
|
NSLog( @"%2d : %llu", i, sylv )
|
|
sum = sum + 1 / (double)sylv
|
|
next
|
|
NSLog( @"\nSum of the reciprocals: %.15f", sum )
|
|
end fn
|
|
|
|
fn SylvesterSequence( 7 )
|
|
|
|
HandleEvents
|