How to resolve the algorithm Averages/Root mean square step by step in the ALGOL-M programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Root mean square step by step in the ALGOL-M 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 ALGOL-M programming language
Source code in the algol-m programming language
BEGIN
DECIMAL FUNCTION SQRT(X);
DECIMAL X;
BEGIN
DECIMAL R1, R2, TOL;
TOL := .00001; % reasonable for most purposes %
IF X >= 1.0 THEN
BEGIN
R1 := X;
R2 := 1.0;
END
ELSE
BEGIN
R1 := 1.0;
R2 := X;
END;
WHILE (R1-R2) > TOL DO
BEGIN
R1 := (R1+R2) / 2.0;
R2 := X / R1;
END;
SQRT := R1;
END;
COMMENT - MAIN PROGRAM BEGINS HERE;
DECIMAL N, SQSUM, SQMEAN;
SQSUM := 0.0;
FOR N := 1.0 STEP 1.0 UNTIL 10.0 DO
SQSUM := SQSUM + (N * N);
SQMEAN := SQSUM / (N - 1.0);
WRITE("RMS OF WHOLE NUMBERS 1.0 THROUGH 10.0 =", SQRT(SQMEAN));
END
You may also check:How to resolve the algorithm IBAN step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Simple turtle graphics step by step in the Wren programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the Chef programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the Erlang programming language
You may also check:How to resolve the algorithm Sleeping Beauty problem step by step in the Red programming language