Program to find if two numbers and their AM and HM are present in an array using STL | Python3 program to check if two numbers are present in an array then their AM and HM are also present . Finally , find the GM of the numbers ; Function to find the arithmetic mean of 2 numbers ; Function to find the harmonic mean of 2 numbers ; Following function checks and computes the desired results based on the means ; Calculate means ; Hash container ( set ) to store elements ; Insertion of array elements in the set ; Conditionals to check if numbers are present in array by Hashing ; Conditionals to check if the AM and HM of the numbers are present in array ; If all conditions are satisfied , the Geometric Mean is calculated ; If numbers are found but the respective AM and HM are not found in the array ; If none of the conditions are satisfied ; Driver Code
from math import sqrt NEW_LINE def ArithmeticMean ( A , B ) : NEW_LINE INDENT return ( A + B ) / 2 NEW_LINE DEDENT def HarmonicMean ( A , B ) : NEW_LINE INDENT return ( 2 * A * B ) / ( A + B ) NEW_LINE DEDENT def CheckArithmeticHarmonic ( arr , A , B , N ) : NEW_LINE INDENT AM = ArithmeticMean ( A , B ) NEW_LINE HM = HarmonicMean ( A , B ) NEW_LINE Hash = set ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT Hash . add ( arr [ i ] ) NEW_LINE DEDENT if ( A in Hash and B in Hash ) : NEW_LINE INDENT if ( AM in Hash and HM in Hash ) : NEW_LINE INDENT print ( " GM ▁ = " , round ( sqrt ( AM * HM ) , 2 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " AM ▁ and ▁ HM ▁ not ▁ found " ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( " Numbers ▁ not ▁ found " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1.0 , 2.0 , 2.5 , 3.0 , 4.0 , 4.5 , 5.0 , 6.0 ] NEW_LINE N = len ( arr ) NEW_LINE A = 3.0 NEW_LINE B = 6.0 NEW_LINE CheckArithmeticHarmonic ( arr , A , B , N ) NEW_LINE DEDENT