How to resolve the algorithm Averages/Root mean square step by step in the ALGOL W 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 W 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 W programming language
Source code in the algol programming language
begin
% computes the root-mean-square of an array of numbers with %
% the specified lower bound (lb) and upper bound (ub) %
real procedure rms( real array numbers ( * )
; integer value lb
; integer value ub
) ;
begin
real sum;
sum := 0;
for i := lb until ub do sum := sum + ( numbers(i) * numbers(i) );
sqrt( sum / ( ( ub - lb ) + 1 ) )
end rms ;
% test the rms procedure with the numbers 1 to 10 %
real array testNumbers( 1 :: 10 );
for i := 1 until 10 do testNumbers(i) := i;
r_format := "A"; r_w := 10; r_d := 4; % set fixed point output %
write( "rms of 1 .. 10: ", rms( testNumbers, 1, 10 ) );
end.
You may also check:How to resolve the algorithm Old Russian measure of length step by step in the Sidef programming language
You may also check:How to resolve the algorithm Factorial step by step in the Ceylon programming language
You may also check:How to resolve the algorithm Sorting algorithms/Stooge sort step by step in the Go programming language
You may also check:How to resolve the algorithm Character codes step by step in the Ruby programming language
You may also check:How to resolve the algorithm Diversity prediction theorem step by step in the XPL0 programming language