Program for harmonic mean of numbers | C # program to find harmonic mean of numbers . ; Function that returns harmonic mean . ; Declare sum variables and initialize with zero ; Driver code
using System ; class GFG { static float harmonicMean ( float [ ] arr , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + ( float ) 1 / arr [ i ] ; return ( float ) n / sum ; } public static void Main ( ) { float [ ] arr = { 13.5f , 14.5f , 14.8f , 15.2f , 16.1f } ; int n = arr . Length ; Console . WriteLine ( harmonicMean ( arr , n ) ) ; } }