Harmonic Progression | C # program to check if a given array can form harmonic progression ; Find reciprocal of arr [ ] ; After finding reciprocal , check if the reciprocal is in A . P . To check for A . P . , first Sort the reciprocal array , then check difference between consecutive elements ; Driver code ; series to check whether it is in H . P ; Checking a series is in H . P or not
using System ; using System . Collections ; class GFG { static bool checkIsHP ( double [ ] arr ) { int n = arr . Length ; if ( n == 1 ) return true ; ArrayList rec = new ArrayList ( ) ; for ( int i = 0 ; i < n ; i ++ ) rec . Add ( ( int ) ( 1 / arr [ i ] ) ) ; rec . Sort ( ) ; int d = ( int ) rec [ 1 ] - ( int ) rec [ 0 ] ; for ( int i = 2 ; i < n ; i ++ ) if ( ( int ) rec [ i ] - ( int ) rec [ i - 1 ] != d ) return false ; return true ; } public static void Main ( ) { double [ ] arr = { 1 / 5 , 1 / 10 , 1 / 15 , 1 / 20 , 1 / 25 } ; if ( checkIsHP ( arr ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }