How to resolve the algorithm Averages/Root mean square step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Averages/Root mean square step by step in the Action! programming language

Table of Contents

Problem Statement

Compute the   Root mean square   of the numbers 1..10.

The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Averages/Root mean square step by step in the Action! programming language

Source code in the action! programming language

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

  

You may also check:How to resolve the algorithm HTTP step by step in the Ruby programming language
You may also check:How to resolve the algorithm Random numbers step by step in the PL/I programming language
You may also check:How to resolve the algorithm Rosetta Code/Find bare lang tags step by step in the Groovy programming language
You may also check:How to resolve the algorithm Plot coordinate pairs step by step in the Processing programming language
You may also check:How to resolve the algorithm Play recorded sounds step by step in the Delphi programming language