Sum of a series: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Modula-2) |
(Added solution for Action!) |
||
Line 64: | Line 64: | ||
(+ (/ (* max-x max-x)) |
(+ (/ (* max-x max-x)) |
||
(sum-x^-2 (1- max-x)))))</lang> |
(sum-x^-2 (1- max-x)))))</lang> |
||
=={{header|Action!}}== |
|||
{{libheader|Action! Tool Kit}} |
|||
<lang Action!>INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit |
|||
PROC Calc(CARD n REAL POINTER res) |
|||
CARD i,st |
|||
BYTE perc |
|||
REAL one,a,b |
|||
IntToReal(0,res) |
|||
IF n=0 THEN RETURN FI |
|||
IntToReal(1,one) |
|||
st=n/100 |
|||
FOR i=1 TO n |
|||
DO |
|||
IF i MOD st=0 THEN |
|||
PrintB(perc) Put('%) PutE() Put(28) |
|||
perc==+1 |
|||
FI |
|||
IntToReal(i,a) |
|||
RealMult(a,a,b) |
|||
RealDiv(one,b,a) |
|||
RealAdd(res,a,b) |
|||
RealAssign(b,res) |
|||
OD |
|||
RETURN |
|||
PROC Main() |
|||
REAL POINTER res |
|||
CARD n=[1000] |
|||
Put(125) PutE() ;clear screen |
|||
Calc(n,res) |
|||
PrintF("s(%U)=",n) |
|||
PrintRE(res) |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Sum_of_a_series.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
s(1000)=1.64392967 |
|||
</pre> |
|||
=={{header|ActionScript}}== |
=={{header|ActionScript}}== |