How to resolve the algorithm Averages/Root mean square step by step in the SparForte programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Root mean square step by step in the SparForte 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 SparForte programming language
Source code in the sparforte programming language
#!/usr/local/bin/spar
pragma annotate( summary, "calcrms" )
@( description, "Compute the Root mean square of the numbers 1..10." )
@( description, "The root mean square is also known by its initial RMS (or rms), and as the" )
@( description, "quadratic mean. The RMS is calculated as the mean of the squares of the" )
@( description, "numbers, square-rooted" )
@( see_also, "http://rosettacode.org/wiki/Averages/Root_mean_square" )
@( author, "Ken O. Burtch" );
pragma license( unrestricted );
pragma restriction( no_external_commands );
procedure calcrms is
type float_arr is array(1..10) of float;
list : constant float_arr := (1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0);
total: float := 0.0;
rms : float;
begin
for p in arrays.first(list)..arrays.last(list) loop
total := @ + list(p)**2;
end loop;
rms := numerics.sqrt( total / float(arrays.length(list)));
? rms;
end calcrms;
You may also check:How to resolve the algorithm Tokenize a string step by step in the Fantom programming language
You may also check:How to resolve the algorithm Loops/For step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Price fraction step by step in the Oz programming language
You may also check:How to resolve the algorithm Function definition step by step in the Slate programming language
You may also check:How to resolve the algorithm Thue-Morse step by step in the AWK programming language