Program to calculate the value of sin ( x ) and cos ( x ) using Expansion | Function for calculation ; Converting degrees to radian ; maps the sum along the series ; holds the actual value of sin ( n ) ; Driver Code
< ? php function cal_cos ( $ n ) { $ accuracy = 0.0001 ; $ n = $ n * ( 3.142 / 180.0 ) ; $ x1 = 1 ; $ cosx = $ x1 ; $ cosval = cos ( $ n ) ; $ i = 1 ; do { $ denominator = 2 * $ i * ( 2 * $ i - 1 ) ; $ x1 = - $ x1 * $ n * $ n / $ denominator ; $ cosx = $ cosx + $ x1 ; $ i = $ i + 1 ; } while ( $ accuracy <= abs ( $ cosval - $ cosx ) ) ; echo round ( $ cosx , 6 ) ; } $ n = 30 ; cal_cos ( $ n ) ; ? >