Program to get the Sum of series : 1 | Function to get the series ; Sum of n - 1 terms starting from 2 nd term ; Driver Code
< ? php function Series ( $ x , $ n ) { $ sum = 1 ; $ term = 1 ; $ fct ; $ j ; $ y = 2 ; $ m ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { $ fct = 1 ; for ( $ j = 1 ; $ j <= $ y ; $ j ++ ) { $ fct = $ fct * $ j ; } $ term = $ term * ( -1 ) ; $ m = $ term * pow ( $ x , $ y ) / $ fct ; $ sum = $ sum + $ m ; $ y += 2 ; } return $ sum ; } $ x = 9 ; $ n = 10 ; $ precision = 4 ; echo substr ( number_format ( Series ( $ x , $ n ) , $ precision + 1 , ' . ' , ' ' ) , 0 , -1 ) ; ? >