Averages/Root mean square: Difference between revisions
Content added Content deleted
(→{{header|BQN}}: Add Under-based solution) |
(Added solution for Action!) |
||
Line 29: | Line 29: | ||
<pre> |
<pre> |
||
6.20484 |
6.20484 |
||
</pre> |
|||
=={{header|Action!}}== |
|||
{{libheader|Action! Tool Kit}} |
|||
<lang Action!>INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit |
|||
BYTE FUNC Equal(REAL POINTER a,b) |
|||
BYTE ARRAY x,y |
|||
x=a y=b |
|||
IF x(0)=y(0) AND x(1)=y(1) AND x(2)=y(2) THEN |
|||
RETURN (1) |
|||
FI |
|||
RETURN (0) |
|||
PROC Sqrt(REAL POINTER a,b) |
|||
REAL z,half |
|||
IntToReal(0,z) |
|||
ValR("0.5",half) |
|||
IF Equal(a,z) THEN |
|||
RealAssign(z,b) |
|||
ELSE |
|||
Power(a,half,b) |
|||
FI |
|||
RETURN |
|||
PROC Main() |
|||
BYTE i |
|||
REAL x,x2,sum,tmp |
|||
IntToReal(0,sum) |
|||
FOR i=1 TO 10 |
|||
DO |
|||
IntToReal(i,x) |
|||
RealMult(x,x,x2) |
|||
RealAdd(sum,x2,tmp) |
|||
RealAssign(tmp,sum) |
|||
OD |
|||
IntToReal(10,x) |
|||
RealDiv(sum,x,tmp) |
|||
Sqrt(tmp,x) |
|||
Put(125) PutE() ;clear screen |
|||
Print("RMS of 1..10 is ") |
|||
PrintRE(x) |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Root_mean_square.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
RMS of 1..10 is 6.20483663 |
|||
</pre> |
</pre> |
||