Program for sum of cos ( x ) series | Javascript program to find the sum of cos ( x ) series ; here x is in degree . we have to convert it to radian for using it with series formula , as in series expansion angle is in radian ; Driver Code
const PI = 3.142 ; function cosXSertiesSum ( x , n ) { x = x * ( PI / 180.0 ) ; let res = 1 ; let sign = 1 , fact = 1 , pow = 1 , i ; for ( i = 1 ; i < 5 ; i ++ ) { sign = sign * - 1 ; fact = fact * ( 2 * i - 1 ) * ( 2 * i ) ; pow = pow * x * x ; res = res + sign * pow / fact ; } return res ; } let x = 50 ; let n = 5 ; document . write ( ( ( cosXSertiesSum ( x , 5 ) * 1000000 ) / 1000000.00 ) . toFixed ( 6 ) ) ;