How to resolve the algorithm Averages/Pythagorean means step by step in the Euphoria programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Averages/Pythagorean means step by step in the Euphoria programming language

Table of Contents

Problem Statement

Compute all three of the Pythagorean means of the set of integers 1 through 10 (inclusive). Show that

A (

x

1

, … ,

x

n

) ≥ G (

x

1

, … ,

x

n

) ≥ H (

x

1

, … ,

x

n

)

{\displaystyle A(x_{1},\ldots ,x_{n})\geq G(x_{1},\ldots ,x_{n})\geq H(x_{1},\ldots ,x_{n})}

for this set of positive integers.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Averages/Pythagorean means step by step in the Euphoria programming language

Source code in the euphoria programming language

function arithmetic_mean(sequence s)
    atom sum
    if length(s) = 0 then
        return 0
    else
        sum = 0
        for i = 1 to length(s) do   
            sum += s[i]
        end for
        return sum/length(s)
    end if
end function

function geometric_mean(sequence s)
    atom p
    p = 1
    for i = 1 to length(s) do
        p *= s[i]
    end for
    return power(p,1/length(s))
end function

function harmonic_mean(sequence s)
    atom sum
    if length(s) = 0 then
        return 0
    else
        sum = 0
        for i = 1 to length(s) do
            sum += 1/s[i]
        end for
        return length(s) / sum
    end if
end function

function true_or_false(atom x)
    if x then
        return "true"
    else
        return "false"
    end if
end function

constant s = {1,2,3,4,5,6,7,8,9,10}
constant arithmetic = arithmetic_mean(s),
    geometric = geometric_mean(s),
    harmonic = harmonic_mean(s)
printf(1,"Arithmetic: %g\n", arithmetic)
printf(1,"Geometric: %g\n", geometric)
printf(1,"Harmonic: %g\n", harmonic)
printf(1,"Arithmetic>=Geometric>=Harmonic: %s\n",
    {true_or_false(arithmetic>=geometric and geometric>=harmonic)})

  

You may also check:How to resolve the algorithm Calculating the value of e step by step in the Pascal programming language
You may also check:How to resolve the algorithm Isqrt (integer square root) of X step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Literals/String step by step in the C programming language
You may also check:How to resolve the algorithm Sequence of primes by trial division step by step in the F# programming language
You may also check:How to resolve the algorithm Almost prime step by step in the APL programming language