Sylvester's sequence: Difference between revisions

→‎{{header|ALGOL 68}}: Corrected spelling of reciprocal - thanks to Gerard Schildberger for showing me the error of my ways...
(Added Prolog solution)
(→‎{{header|ALGOL 68}}: Corrected spelling of reciprocal - thanks to Gerard Schildberger for showing me the error of my ways...)
Line 25:
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses Algol 68G's LONG LONG INT and LONG LONG REAL which have specifiable precision. The sum of the reciprocolsreciprocals in the output has been manually edited to replace a large number of nines with ... to reduce the width.
<lang algol68>BEGIN # calculate elements of Sylvestor's Sequence #
PR precision 200 PR # set the number of digits for LONG LONG modes #
Line 44:
# find the first 10 elements of Sylvestor's Seuence #
[]LONG LONG INT seq = SYLVESTOR 10;
# show the sequence and sum the reciprocolsreciprocals #
LONG LONG REAL reciprocolreciprocal sum := 0;
FOR i FROM LWB seq TO UPB seq DO
print( ( whole( seq[ i ], 0 ), newline ) );
reciprocolreciprocal sum +:= 1 / seq[ i ]
OD;
print( ( "Sum of reciprocolsreciprocals: ", reciprocolreciprocal sum, newline ) )
END
</lang>
Line 65:
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443
Sum of reciprocolsreciprocals: +9.99999999999999999999999999999999999999999...999999999999999999999999999964e -1
</pre>
 
3,048

edits