Sylvester's sequence: Difference between revisions
Content added Content deleted
(Added Sidef) |
m (→{{header|REXX}}: added whitespace and a comment.) |
||
Line 621: | Line 621: | ||
parse arg n . /*obtain optional argument from the CL.*/ |
parse arg n . /*obtain optional argument from the CL.*/ |
||
if n=='' | n=="," then n= 10 /*Not specified? Then use the default.*/ |
if n=='' | n=="," then n= 10 /*Not specified? Then use the default.*/ |
||
numeric digits max(9, 2**(n-7)*13 + 1) |
numeric digits max(9, 2**(n-7) * 13 + 1) /*calculate how many dec. digs we need.*/ |
||
@.0= 2 /*the value of the 1st Sylvester number*/ |
@.0= 2 /*the value of the 1st Sylvester number*/ |
||
$= 0 |
$= 0 |
||
Line 629: | Line 629: | ||
$= $ + 1 / @.j /*add its reciprocal to the recip. sum.*/ |
$= $ + 1 / @.j /*add its reciprocal to the recip. sum.*/ |
||
end /*j*/ |
end /*j*/ |
||
say /*stick a fork in it, we're all done. */ |
|||
say |
|||
numeric digits digits()-1 |
numeric digits digits() - 1 |
||
say 'sum of the first ' n " reciprocals using" digits() 'decimal digits: ' $ / 1</lang> |
say 'sum of the first ' n " reciprocals using" digits() 'decimal digits: ' $ / 1</lang> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |