Program for harmonic mean of numbers | C ++ program to find harmonic mean . ; Function that returns harmonic mean . ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float harmonicMean ( int arr [ ] , int freq [ ] , int n ) { float sum = 0 , frequency_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + ( float ) freq [ i ] / arr [ i ] ; frequency_sum = frequency_sum + freq [ i ] ; } return frequency_sum / sum ; } int main ( ) { int num [ ] = { 13 , 14 , 15 , 16 , 17 } ; int freq [ ] = { 2 , 5 , 13 , 7 , 3 } ; int n = sizeof ( num ) / sizeof ( num [ 0 ] ) ; cout << harmonicMean ( num , freq , n ) ; return 0 ; }