Sum of a series: Difference between revisions
Content added Content deleted
(add RPL) |
Deadmarshal (talk | contribs) (Added Oberon-02) |
||
Line 2,024: | Line 2,024: | ||
{{out}} |
{{out}} |
||
<pre>1.643934566681561</pre> |
<pre>1.643934566681561</pre> |
||
=={{header|Oberon-2}}== |
|||
{{trans|Modula-2}} |
|||
<syntaxhighlight lang="oberon2">MODULE SS; |
|||
IMPORT Out; |
|||
TYPE |
|||
RealFunc = PROCEDURE(r:REAL):REAL; |
|||
PROCEDURE SeriesSum(k,n:LONGINT;f:RealFunc):REAL; |
|||
VAR |
|||
total:REAL; |
|||
i:LONGINT; |
|||
BEGIN |
|||
total := 0.0; |
|||
FOR i := k TO n DO total := total + f(i) END; |
|||
RETURN total |
|||
END SeriesSum; |
|||
PROCEDURE OneOverKSquared(k:REAL):REAL; |
|||
BEGIN RETURN 1.0 / (k * k) |
|||
END OneOverKSquared; |
|||
BEGIN |
|||
Out.Real(SeriesSum(1,1000,OneOverKSquared),10); |
|||
Out.Ln; |
|||
END SS. |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre>1.64393E+00 |
|||
</pre> |
|||
=={{header|Objeck}}== |
=={{header|Objeck}}== |