Program to find the sum of the series ( 1 / a + 2 / a ^ 2 + 3 / a ^ 3 + ... + n / a ^ n ) | Function to return the sum of the series ; variable to store the answer ; Math . pow ( x , y ) returns x ^ y ; Driver code ; Print the sum of the series
< ? php function getSum ( $ a , $ n ) { $ sum = 0 ; for ( $ i = 1 ; $ i <= $ n ; ++ $ i ) { $ sum += ( $ i / pow ( $ a , $ i ) ) ; } return $ sum ; } $ a = 3 ; $ n = 3 ; echo ( getSum ( $ a , $ n ) ) ; ? >