Jump to content

Sum of a series: Difference between revisions

→‎{{header|Ruby}}: use 'sum' and Rational
No edit summary
(→‎{{header|Ruby}}: use 'sum' and Rational)
Line 2,649:
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">puts (1..1000).injectsum{ |sum, x| sum + 1.01r / x ** 2 }.to_f</syntaxhighlight>
{{out}}
<pre>
1,149

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.